4. Quoting and evaluation
Literal values, recursive quotation and evaluating constructed transforms.
sUTL · Guide · Reference · Examples
Because code and data share the same representation, sUTL needs explicit ways to delay evaluation and to evaluate constructed transforms.
Literal values with :
The colon form returns its value without traversing it:
{":": "^$.name"}
This returns the string "^$.name" rather than following the path.
Recursive quotation with '
The quote form walks a structure while suppressing ordinary evaluation.
Double quote '' escapes back into evaluation:
{
"'": {
"literal": "^$.value",
"evaluated": {"''": "^$.value"}
}
}
With {"value": 42}, the result is:
{
"literal": "^$.value",
"evaluated": 42
}
Evaluating a constructed transform with !
! evaluates its value to obtain another transform, adds the remaining map
members to scope, and evaluates that transform:
{
"!": {"'": ["&+", "^@.x", "^@.y"]},
"y": 3
}
With {"x": 2}, this returns 5.
The explicit !! form
The later Studio dialect separates the next transform from its scope delta:
{
"!!": {":": {"answer": "^@.value"}},
"s": {"value": 7}
}
Result:
{"answer": 7}
Prefer this form for new higher-order code: it is clearer about what becomes scope. The production Python 2 port omitted it, while Studio/HaxeJS contained a scope-merge bug; the original site and handwritten JavaScript establish the intended behavior.
Why quote appears around callbacks
Dictionary members are evaluated before a builtin receives its scope. A
callback passed to if or reduce must normally be quoted once so the builtin
can evaluate it later in the correct scope.
Next: Scope and reduction.
Continue learning
Previous: 3. Builtins · Guide contents · Language reference
Source
Adapted from the sUTL source material.