Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: engine compatibility

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

Info
titleEngine Compatibility

The syntax for use with the node pico engine differs. There is no clear (but you can assign a null), and setting is done with a := infix operator.


The following statements mutate persistent variables:

...

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.  


Warning

For historical reasons, if the persistent variable does not exist before it is used, the default value is 0. 

This means that the isnull() operator, for example, is never true for an entity variable.

Warning

Numbers don't behave well as persistent variable indexes for maps. This is due to the underlying Mongo implementation treating them as array references rather than as map (hash) keys. In general, prepending or appending a string to the number will fix the problem.

 


Examples

 For classic KRE:

Code Block
languagejavascript
themeConfluence
languagejavascript
fired {
  set ent:a 1
  set app:b{"foo"} 1 + my_var
  set app:b{["flip", "flop"]} "this is a string"
  clear c
}

This blog post has a detailed example of using persistent variables to create a personal data manager. 

For the node pico engine:

Code Block
fired {
  ent:a := 1;
  app:b{"foo"} := 1 + my_var;
  app:b{["flip", "flop"]} := "this is a string";
  ent:c := null
}


Deprecated

Info
titleDeprecated

The following are deprecated and should not be used.  


There are several persistent statements that are deprecated. 

...