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β
| Escape | Value |
|---|---|
\n | Newline |
\r | Carriage return |
\t | Tab |
\" | 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("eΜ")
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 "eΜ" 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.