Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Strings

String literals and backslash escapes are part of the language syntax. Formatting and conversion are explicit library calls; a plain string containing {name} stays unchanged.

OperationKindResult
to_string(value)ControlString
format(template)ControlString
concat(first, rest...)FunctionString
length(text)FunctionInteger
contains(text, search)FunctionBoolean
starts_with(text, prefix)FunctionBoolean
ends_with(text, suffix)FunctionBoolean

to_string

Evaluates one runtime value and converts it to text:

ValueRepresentation
StringIts contents, without surrounding quotes
Integer or finite floatDecimal text
Booleantrue or false
nonenull
ArrayCompact JSON array
RecordCompact JSON object, in field declaration order
print(to_string(array_of(1, 2, 3))) / [1,2,3]
record(Person, field(name, string), field(age, integer))
print(to_string(record_of(Person, "Ada", 37))) / {"name":"Ada","age":37}

Inside arrays and records, strings are quoted and escaped as JSON. Optional fields containing none appear as null; they are not omitted. Shared objects can appear more than once, but an object cycle causes an error. Formatting also fails for non-finite floats, invalid object references, or more than 128 levels of nested objects. Descriptors and expressions producing no value are not accepted.

Conversion does not preserve type identity: 1.0 can become "1", and records carry no type name in their JSON representation. No JSON parsing operation is currently provided.

format

Evaluates one string template, then replaces {name} placeholders using normal name lookup in the current lexical scope. Values are converted using to_string. Only identifiers are accepted inside placeholders; expressions, field paths, and whitespace are not allowed.

declare(name, string, "Ada")
declare(score, integer, 42)
print(format("{name} scored {score}.")) / Ada scored 42.
print(format("{{score}} = {score}")) / {score} = 42

Write {{ and }} to insert literal braces. An empty placeholder, unmatched brace, unknown name, uninitialized variable, or name resolving to a type causes an error. Conversion errors from to_string also propagate. Replacement text is inserted as-is and is not scanned for further placeholders.

The template can be computed rather than written as a literal; it is evaluated once. Lookup follows lexical scope, including shadowing and a script Function’s captured environment.

concat

Joins one or more strings in argument order. A single argument is returned unchanged. Zero arguments or non-string arguments have no matching signature. Conversions must be explicit:

print(concat("Score: ", to_string(42))) / Score: 42

length

Returns the number of Unicode scalar values, not UTF-8 bytes or displayed characters. A combining mark counts separately from its base character.

print(length("hello")) / 5
print(length("\u{1F989}")) / 1
print(length("e\u{301}")) / 2

An unrepresentable length would cause an integer-range error.

contains

Tests whether the search string occurs anywhere in the text. Matching is case-sensitive and does not normalize Unicode. An empty search string matches.

print(contains("Hello DETLEF", "DETLEF")) / true

starts_with

Tests for an exact prefix. An empty prefix matches.

print(starts_with("DETLEF", "Det")) / true

ends_with

Tests for an exact suffix. An empty suffix matches.

print(ends_with("example.dtf", ".dtf")) / true

Both prefix and suffix matching are case-sensitive and do not normalize Unicode. All five string Functions require string arguments; see Function arguments.