sUTL
Guide · 04 / 07

4. Quoting and evaluation

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.

Interactive conformance example: JavaScript is required to edit and run it.

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
}

Interactive conformance example: JavaScript is required to edit and run it.

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.

Interactive conformance example: JavaScript is required to edit and run it.

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.

Interactive conformance example: JavaScript is required to edit and run it.

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.