Internal Stack
{[ 3 | .last-comments(1) | .comment-template | .show-comments(2) ]} | (i-1) |
An Nzymes injection is an expression written following the Reverse Polish notation. A calculator for results of such expressions is easy to implement and quite powerful. All you need is a stack, which is a LIFO data structure: last in, first out. Therefore, Nzymes manages its enzymes by means of an internal stack. The structure of an injection reflects how the internal stack changes during its interpretation.
- ´{[´
Nzymes finds the start of a new injection and creates an (empty) internal stack.
Stack: <>. - ´{[3´
Nzymes finds a literal number and pushes it onto the internal stack.
Stack: <3>. - ´{[3|.last-comments(1)´
Nzymes pops 1 item (the number 3), runs the code from a custom field, and pushes the result (be it A) onto the internal stack.
Stack: <A>. - ´{[3|.last-comments(1)|.comment-template´
Nzymes pushes the value (be it B) from a custom field onto the internal stack.
Stack: <A B>. - ´{[3|.last-comments(1)|.comment-template|.show-comments(2)´
Nzymes pops 2 items, runs the code from a custom field, and pushes the result (be it C) onto the internal stack.
Stack: <C>. - ´{[3|.last-comments(1)|.comment-template|.show-comments(2)]}´
Nzymes finds the end of the current injection, replaces all the injection with a popped item, and destroys the internal stack.
Stack: <>.
Note that it’s not completely by chance that the (i-1) injection processing ends with an empty internal stack. In fact RPN calculators consider that a final non-empty stack is an error condition. The practical reason is that you are supposed to push on the stack only something that is going to be used later. If something couldn’t be used before the end of the expression, there should be an error somewhere. In Nzymes that is only considered best practice and a final non-empty internal stack is not an error.
|
|
Nzymes | WordPress Plugin |
© 2015 by Andrea Ercolino |