Mutating Persistents in the Postlude

To be useful, persistent variables must be mutated. Persistents can only be mutated in the postlude.

The following statements mutate persistent variables:

  • clear <pvar>. This deletes the persistent variable <pvar>
  • <pvar> := <expr>. This assigns the value of <expr> to the persistent variable <pvar>.

If the persistent variable is bound to a complex data structure (i.e. maps and arrays), <pvar> can contain a hash path referencing part of the structure (see example below). 

Example

always {
  ent:a := 1; 										// sets entity variable "a" to 1
  app:b{"foo"} := 1 + my_var.defaultsTo(0); 		// sets top-level key "foo" in the map inside of app variable "b"
  ent:b{["flip", "flop"]} := "this is a string"; 	// hash path into map inside of entity variable "b" (sets the value keyed to "flop" which is keyed to "flip")
  ent:c := null;									// sets entity variable to null
  clear ent:a										// clears the entity variable so it does not exist
}

Copyright Picolabs | Licensed under Creative Commons.