Open b1conrad opened 3 years ago
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."
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 anevery
compound action).For one example, the
ctx:newChannel
built-in action returns the entire channel mapbut what we'll need in subsequent actions will most likely be just the channel ID (aka ECI)
so it would be useful notation to be able to place bindings between actions, like so:
This makes coding clearer and eliminates repetitions of the sub-expression because it can be bound to a name.