Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Remove old 'ent:<var>{path} :='-like syntax, fix raise

...

Code Block
languagejavascript
themeConfluence
ent:var_a + 1            // add one to the value stored in variable
ent:var_b{"x"}           // retrieve value stored in variable with key "x"
ent:var_c.put(["y"], 10) // storemake a new map from var_c with 10 stared at key "y"
in variable
ent:var_d[4]             // retrieve value in array at index 4

...

  • clear <pvar>. This deletes the persistent variable <pvar>
  • <pvar> := <expr>. This sets the value of <pvar> to the value of the expression (literal).

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. 

Persistent variables are scoped within a ruleset. One ruleset cannot see another ruleset's persistent variables. That might seem like a significant limitation, but it's easily overcome using modules. 

...

To see how this works and why it's important, consider a module defined to act as a persistent data module (PDM). The PDM ruleset has a rule that is listening for the pds:new_data event.

Code Block
languagejavascript
themeConfluence
rule add_data_item {
  select when pds new_data
  pre {
    k = event:attr("key");
    val = event:attr("value")
  }
  always {
    ent:data{k} := ent:data.put(k, val);
    raise pds event "data_added"
      withattributes key = k{"key":k};
  }
}

This rule does two things when it sees a salient event (note this rule has no action, just a postlude):

...