Syntax Experiments
One way I’ve been working on Klee, is to sketch out example programs and explain how they should behave, before the implementation can sufficiently execute the commands I’m drawing out.
During
The during
keyword is used in proper syndicate implementations, and plays the same roll in Klee. It takes the default form:
(during P <E_b> <E> <E_r>)
-
P is the pattern we are matching the dataspace against
-
E_b denotes “expression before” and is the expression run for a defined amount of time “before” the assertion appears. The idea here is to have three dedicated lifetimes of a shape “before” “during” and “after”. Because we cannot predict the future, before instead needs to start when the assertion is first asserted, and as mentioned previously, lives for a defined amount of time in this state. One major use case for this is fade-in animations.
-
E expression is executed once the specified lifetime of E_b is over. This is the core behavior of the during expr, and this is where most of the main draw commands will be made.
-
E_r is the expr fired when the assertion is retracted. This is mostly for cleanup or error handling etc.
Except
The opposite of during
, fires whenever there is no matching assertions to the pattern.
(except P <E_b> <E> <E_r>)
Same idea as during but logically opposite, e.g. P is the pattern, E_b is run for a set amount of time starting whenever the expression is true. E runs as it is true, and E_r is run once a matching assertion is found.
Collect
Reactively collects all matching assertions and puts them into a sorted list.
(collect P)
Used to create reactive lists which can then be mapped over to draw shapes per each element. I generally like this approach better than instead having actors assert and update list data directly because if there is a very large list that is not often changed, a lot of bandwidth is wasted sending the entire list to only actually update a few entries. This strategy means only the direct changes to the list items are passed around.