pico-engine
pico-engine copied to clipboard
Language change to allow bindings interleaved with actions with `every` compound action
Actions and defactions can return a result, which can be bound to a name with a setting
clause. Often the result isn't directly useful to subsequent actions in the sequence (in an every
compound action).
For one example, the ctx:newChannel
built-in action returns the entire channel map
ctx:newChannel(tags,eventPolicy,queryPolicy) setting(channel)
but what we'll need in subsequent actions will most likely be just the channel ID (aka ECI)
ctx:delChannel(channel{"id"})
so it would be useful notation to be able to place bindings between actions, like so:
every {
ctx:newChannel(tags,eventPolicy,queryPolicy) setting(channel)
eci = channel{"id"}
... // including uses of eci
ctx:delChannel(eci)
}
This makes coding clearer and eliminates repetitions of the sub-expression because it can be bound to a name.
Here's a real example, with names rid
, eci
, and res
bound to an expression based on a returned result. Rather than having to repeat the expression every time it is needed, I can just use the name.
The left hand side shows a function and a defaction without this feature. The RHS shows the simpler code that I would like to be able to write in KRL.
Orange highlighting shows the three times rid
is used, yellow for eci
used twice. Purple shows how res
is used once to make the code clearer by calling out an expression that would otherwise have to be embedded.
Matthew says, "#528 seems like a good idea. It'll require changes to the krl-parser
and the krl-compiler
the runtime probably won't need any changes."