Strings

Single and double quotes are interchangeable; both support interpolation, escape sequences, format specs, and raw variants.

Summary

Expressions inside {braces} are evaluated and embedded inline. An optional :specafter the expression controls formatting, following Python's mini-language for width, alignment, precision, and base. Triple-quoted strings handle multi-line text with automatic indentation stripping. Raw strings (r"...") skip all escape processing and interpolation. Color strings (c"bold;red;text") embed ANSI sequences at parse time. Concatenation uses ++.

Canonical

Both single and double quotes create strings. They're identical: both support interpolation and escape sequences.

let s = "hello world"
let s2 = 'also a string'

Interpolation

Expressions inside {braces} are evaluated and embedded.

let name = "XS"
println("Hello, {name}!")         -- Hello, XS!
println("{1 + 2} is three")       -- 3 is three
println("{name} has {len(name)} chars")  -- XS has 2 chars

-- escape the brace to get a literal {
println("\{not interpolated}")    -- {not interpolated}

Format Specs

After the expression, an optional :spec controls how the value is rendered. Spec syntax follows Python's mini-language: {value:[fill][align][width][,][.prec][type]}.

let pi = 3.14159
println("{pi:.2}")                -- 3.14
println("{pi:8.2}")               -- "    3.14"
println("{pi:<8.2}")              -- "3.14    "
println("{pi:^8.2}")              -- "  3.14  "
println("{pi:.2%}")               -- 314.16%

let n = 1234567
println("{n:,}")                  -- 1,234,567
println("{255:x}")                -- ff
println("{255:X}")                -- FF
println("{8:b}")                  -- 1000
println("{8:o}")                  -- 10

-- Fill char before the alignment marker
println("{42:0>5}")               -- 00042

Escape Sequences

EscapeCharacter
\nNewline
\tTab
\rCarriage return
\\Backslash
\"Double quote
\'Single quote
\0Null byte
\aBell
\bBackspace
\fForm feed
\vVertical tab
\eESC (0x1B)
\{Literal { (suppresses interpolation)

Any other \x passes through unchanged.

Triple-Quoted Strings

Multi-line strings with automatic indentation handling.

let text = """
    line one
    line two
"""
println(text.contains("\n"))     -- true

Triple-quoted strings still support interpolation. Use r"""...""" for raw triple-quoted.

Raw Strings

No escape processing, no interpolation.

let pattern = r"\d+\.\d+"
println(pattern)                 -- \d+\.\d+

let x = 42
let raw = r"no {x} here \n raw"
println(raw)                     -- no {x} here \n raw

Color Strings

Embed ANSI terminal colors at parse time. Format: c"style;style;...;text": the last segment is the text, everything before it is styling.

let err = c"bold;red;Error!"
let ok  = c"green;Success"
println(err)                     -- prints "Error!" in bold red

A reset sequence is appended automatically.

Available styles:

CategoryValues
Attributesbold, dim, italic, underline, blink, reverse, hidden, strikethrough
Foregroundblack, red, green, yellow, blue, magenta, cyan, white
Bright FGbright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white
Backgroundbg_black, bg_red, bg_green, bg_yellow, bg_blue, bg_magenta, bg_cyan, bg_white
Bright BGbg_bright_black, bg_bright_red, etc.
256-colorfg256,N, bg256,N (N = 0-255)
Truecolorrgb,R,G,B, bgrgb,R,G,B

Color strings support interpolation in the text part: c"bold;x = {x}".

String Concatenation

"hello" ++ " world"              -- "hello world"
"a" ++ "b" ++ "c"               -- "abc"

Strings concatenate with either ++ or +; ++ is the canonical form so it's clear at the call site that the operands are strings.