Skip to content

3a. Expressions

Martin Halfar edited this page Jan 17, 2021 · 2 revisions

Results:

  • Expressions always result into single value.
  • Wrap results in array [] or object {} to return more than one result from an expression.

Sub-Expressions:

  • You can pack multiple expressions into one by joining them using ;.
  • The last expression is always used to calculate the overall result while the other expressions can be accessed via ~D variables where D is the number of the expression from the left starting with 0.
    For example: 15; 15; ~0 + ~1 will result into 30.
  • You can use the results from sub-expressions any number of times since they are calculated only once. This can be beneficial if you have to use the same result multiple times in single expression or to avoid use of expressions that are not cache-able.

Cache-able Expressions:

  • All expressions that do not involve use of var and header keywords and that are not called in a scope.
    Scope is used as an additional context for the expression and can be different across several calls, therefore the result cannot be cached.
    This behavior can be seen when calling functions as all of their calls will have different scope.

Node Tree:

  • Every expression is converted from plain string to node tree. This tree is checked if it can be cached and then it's post-processed.
  • Result will be retrieved from cache if it exist, otherwise it will get evaluated and stored in cache (if is cache-able).
  • Check this out: Expression tester

Post Processing:

  • Every expression is post processed when converted from plain string to node tree. Every node within this tree is checked whether it can be evaluated without any additional context (simple operations on constant numbers or strings) and if so, it will be automatically evaluated.