Skip to main content

Strings

Strings are immutable UTF-8 text values written with double quotes:

assign name "world 🌍"
show "Hello, " + name + "!"

Output: Hello, world 🌍!. Variables infer the string type. Empty strings ("") are valid, and show prints text without quotes followed by a newline. Percent signs are ordinary text, including %s and %n.

Escapes​

EscapeValue
\nNewline
\rCarriage return
\tTab
\"Double quote
\\Backslash
show "line one\nline two"
show "She said \"hello\"."
show "A backslash: \\"

Put Unicode characters directly in the source. A string must close on the same source line; use \n for embedded newlines. Unclosed quotes and unsupported escapes produce source diagnostics. NUL characters, including \0, and \u / \x escapes are not supported.

Concatenation and equality​

+ joins two strings. == and != compare contents:

assign greeting "Hello, " + "world"
show greeting + "!"
show greeting == "Hello, world"
show greeting != "Goodbye"

Output: Hello, world!, true, true.

String operations require two strings. "count: " + 3 is a type error; numbers and booleans are not implicitly converted. Ordering comparisons, other arithmetic, interpolation, indexing, slicing, and string arrays are not implemented.

Unicode length​

len(string) returns the number of Unicode scalar values:

show len("")
show len("hello")
show len("é中🌍")
show len("é")

Output: 0, 5, 3, 2. The last example contains e followed by a combining accent. A combining mark counts separately, even when the result looks like one character. len does not count bytes or grapheme clusters. Text is not normalized: precomposed "é" and combining "é" compare as different strings.

Reassignment and value semantics​

assign original "hello"
assign saved original
reassign original original + "!"
show saved
show original

Output: hello, then hello!. Reassignment changes the variable's value; previous copies retain their text. A string variable cannot be reassigned a number or boolean.

String functions​

Use string in parameter and return annotations:

function greet(name: string) -> string {
assign prefix "Hello, "
return prefix + name + "!"
}
show greet("Ψ―Ω†ΫŒΨ§ 🌍")

Output: Hello, Ψ―Ω†ΫŒΨ§ 🌍!. Returned strings remain valid after function locals go out of scope. The usual function return rules apply.

Storage and debugging​

The current backend copies string contents on identifier reads and releases temporary values, old reassigned values, function parameters, and locals at scope exit. Loop-local allocations are released on every iteration. Strings use heap storage; repeated concatenation copies the growing text and can take quadratic time. Allocation or size failures terminate with a runtime diagnostic.

Compile with --debug and use frame variable name in LLDB to inspect the text. See native debugging and the compiler's complete string example.