Skip to content

String interpolation

String literals support interpolation via ${...}. Any expression is valid inside the braces.

let name = "Alice"
let age = 30
let greeting = "Hello, ${name}!"
let summary = "${name} is ${age} years old"
let calc = "${a} * ${b} = ${a * b}"

The embedded expression is evaluated and converted to a String via the same stringification rules used by debug.

"path = ${home.join("/")}" // method call
"factorial(5) = ${factorial(5)}" // function call
"${if x > 0 { "positive" } else { "negative" }}" // if-expression
"${match status { Ok(v) => v.toString(), Error(_) => "err" }}" // match

If the expression is itself a string, interpolation recurses naturally; no special handling is required.

String literals support the usual escapes plus one for the interpolation metacharacter:

EscapeProduces
\"double-quote
\\backslash
\nnewline
\rcarriage return
\ttab
\$literal $
let literal = "price is \$${price}" // price is $10

Double quotes inside an interpolated expression do not need escaping; the interpolation delimiter is }, not ".

debug "name=${user.map(fn(u) { u.name }).unwrapOr("anonymous")}"

Raw string literals (without escape processing) are not currently supported. Use explicit escapes where needed.

Interpolations desugar into string concatenation at compile time. The generated Apex does not use String.format; it uses the + operator with stringified operands, which matches Apex’s own preferred idiom.