Use double quotes for normal text:
greeting = "Hello"
Expression-position backtick strings aren't implemented. Use an ordinary string with escapes when the text contains backslashes:
windows_path = "C:\\docs\\site"
Use single quotes for one character:
seedling = '🦋'
Use a template when text needs values or a larger structure:
name = "Priya"
greeting = [:
Hello, [name]
]
Joining strings
Use templates to join strings together. Put the parts inside square brackets:
first = "Hello, "
second = "world"
message = [first, second]
Don't use + to join strings. + is for numbers only. Use templates to concatenate strings.
Read-only strings
A quoted string like "Hello" is read-only content. You can reassign a mutable binding to point at a different string, but you can't change the string itself.
Square brackets belong to templates. Collections use curly braces instead.
Moth has two string source forms and one character form. Both string forms share one semantic String type at ordinary typed boundaries.
escaped_slice = "Hello\nworld"
letter = '🦋'
name = "Priya"
message = [:
Hello, [name]
]
Quoted string slices
Double quotes create escaped string slices. They support exactly these escapes:
\\ for a backslash\" for a double quote\n for a newline\r for a carriage return\t for a tab
Every other escape is invalid. A backslash can't continue a quoted string across a physical newline.
A quoted string slice is read-only content. It has no character or substring mutation surface and isn't concatenated with +. A slice may be read, compared, passed, returned, stored and inserted into templates. A mutable binding that currently holds a slice may be reassigned. That doesn't make the slice contents mutable.
name ~= "Priya"
name = "Aisha"
Characters
Single quotes create Char values.
Template strings
Square brackets create string templates. Templates produce owned string values and may fold at compile time or lower to runtime string construction.
Templates are the idiomatic and canonical way to:
- concatenate strings
- interpolate values
- build runtime or compile-time text
- produce strings that need full template composition
first = "Hello, "
second = "world"
message = [first, second]
name = "Priya"
greeting = [: Hello, [name]]
Use [left, right] for concatenation. Don't use +:
joined = [left, right]
joined = left + right
Source String + String is invalid. The accepted rule is that + is a numeric operator only and the compiler should reject all string + forms. The current compiler still accepts source string + and construction-origin-dependent equality checks. Stage B removes both. See progress matrix for the current implementation gap.
One semantic String type
Quoted slices and template-produced strings share one String type at ordinary typed boundaries. They share:
- parameter and return compatibility
- equality
- choice payload equality
- collection and map value use
String map-key use- casts
- IO and external
StringContent boundaries - template insertion
- aliases and generic use where
String is concrete
Construction origin doesn't create hidden equality, hashing, map-key or call-compatibility rules.
Equality
String supports is and is not. String doesn't support ordering operators (<, <=, >, >=).
slice = "hello"
template = [: hello]
same = slice is template
Binding reassignment versus content mutation
A mutable binding that holds a string can be reassigned. Quoted slices are immutable. Templates produce owned String values. The current source surface does not yet expose in-place string mutation operations.
text ~= "initial"
text = "replacement"
Templates
Templates own interpolation, formatting, slots, wrappers and structured content. See Templates for the complete system.
Quoted slices and templates both participate in the language's String surface. Expression-position raw backtick slices aren't implemented. Inside a template body, backticks, backslashes and physical newlines are ordinary body text available to the active formatter.