Syntax

Kind

Construction

String Literals

String Concatenation

Conversion to String

string

A string represents an immutable sequence of Unicode characters. Strings are used for textual data, identifiers, labels, and human-readable values. They are first-class values and integrate naturally with records, tuples, tables, maps, and comprehensions.

Syntax

String literals are written using double quotes ".

"""Hello, world!""Multi
Line
String""Unicode: πŸ€–πŸ¦ΎπŸ¦Ώ"

Strings may contain spaces and punctuation. Whitespace inside a string literal is preserved.

Escape sequences may be used for special characters:

"line 1\nline 2"
"quote: \""
"tab\tseparated"
"backslash: \\"

When rendered:

"line 1
line 2""quote: """tab	separated""backslash: \"

Raw string literals can be created using triple double quotes """. In this form, escape sequences are not processed, and all characters are taken literally, including backslashes and quotes.

"""C:\Users\Name\Documents"""
"""This is a "raw" \string\ literal."""

When rendered:

"C:\Users\Name\Documents""This is a "raw" \string\ literal."

Kind

Strings have the kind:

<string>

All string values share the same kind regardless of length or contents.

Construction

Strings can be constructed in the following ways:

  • String literals

  • Results of string operations

  • Conversion from other kinds

String Literals

String literals are written using double quotes " and may contain escape sequences and newlines:

"Hello""This is a string literal.""This is a multiline
string literal""This string contains a newline:
See?"

Raw string literals are written with triple quotes and can contain unescaped characters, as well as newlines:

"C:\Program Files\Mech""This is a raw string literal.It can span multiple lines
and include "quotes" and \backslashes\ without needing escapes."

String Concatenation

Strings can be concatenated using the + operator:

first:="Hello"second:="World"greeting:=first+", "+second+"!"

String concatentation is broadcast element-wise over matrices of strings:

prefix:="Item"letters:=[
"A"
"B"
"C"
]
labels:=prefix+letters

If both operands are matrices of strings, they must have compatible dimensions:

m1:=[
"a" "c"
"b" "d"
]
m2:=[
"1" "3"
"2" "4"
]
result:=m1+m2

Conversion to String

All values can be converted to strings explicitly.

x:=42s<string>:=x

Use <[string]> to create a matrix of strings:

m<[string]:2,2>:=[
1
2
3
4
]

This converts a <[f64]:1,4> (row matrix of floats) to a <[string]:2,2> (square matrix of strings).