Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Remove KRE documentation

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

...

titleEngine Compatibility

The

...

The following statements mutate persistent variables:

  • clear <pvar>. This deletes the persistent variable <pvar>
  • set <pvar> := <expr>. This sets assigns the value of <pvar> to the value of the expression (literal). <expr> to <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. 
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:

...

languagejavascript
themeConfluence

Example


Code Block
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.defaultsTo(0);
  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. 

...


  clear ent:a
}