The code formulas can be considered a functional programming language. They cannot have side effects. They only represent computation, the result of which sets the cell value.
Macros are an imperative layer on top of this functional layer. They are purely about side effects, e.g. setting the code formula of some cell. The following are all equivalent conceptually:
The simplest macro syntax:
SetLabel! a, R3C0;
PasteCell! a, 1&2;
Unlike function calls, macros cannot nest, so:
Sum(T(1&2)) -> OK!
PastCell! (SetLabel! a, R3C0), 1&2; -> Not OK!
Each macro command can either call a primitive, or a macro node. Primitives are provided by the system, like SetLabel
. A macro node is user defined.
Users can define custom macro command using macro nodes. A macro node sits in the tree hierarchy just like an ordinary sheet, but it contains only a piece of macro code, which calls other primitives and macro nodes to do the actual work.
P.on_submit! Xuser, Xquestion_id, Xanswer;
TODO with
statement
TODO if
statement
TODO for
statement
SetLabel! label_name, cell_reference;
PasteCell! cell_reference, value;
value is evaluated, and the cell's formula is set to the evaluated value. E.g.