String literals
Simple literals
String literals are bounded by double quotes (").
They support the same escape sequences as JSON.
"quote" strings
The quote keyword introduces an indented multi-line string.
These support escape sequences and interpolation too.
Interpolation
String interpolation works with any type that defines a show function.
Interpolated values go in braces ({}).
Interpolating other types
Other string-like types support interpolation too.
Interpolating custom types
For json and symbol, interpolation just creates a string and converts it to the appropriate type.
But custom interpolation can also be used to have different behavior for interpolated values.
Defining custom interpolation involves 3 parts:
- An
interpolate-stringfunction that prepares a literal part. (This means a part not inside{}.)
This can return any type. - An
interpolate-valuefunction that prepares an interpolated part. (This means a part inside{}.)
This must return the same type asinterpolate-string. - An
interpolatefunction that combines all parts into a result.
"a{b}c" is equivalent to:
interpolate (
"a".interpolate-string,
b.interpolate-value,
"c".interpolate-string)
For strings, interpolate-string is the identity function, while
interpolate-value calls show.
Notice how id got quoted by interpolate-value.