Expressions and Operators
Arithmetic
Section titled “Arithmetic”Operators +, -, *, /, % work on int and float. Integer division truncates. Mixed int/float operations promote to float.
10 + 3 # 1310 / 3 # 3 (int division truncates)10.0 / 3 # 3.333... (mixed promotes to float)10 % 3 # 1 (modulo)String Concatenation
Section titled “String Concatenation”The ~ operator (D-style) concatenates strings:
let full = "hello" ~ " " ~ "world"let path = HOME ~ "/docs"String Interpolation
Section titled “String Interpolation”Double-quoted strings support interpolation. In expression context (assignments, conditions, lambdas), variables are accessed by bare name without $. The $ prefix is required only inside double-quoted strings.
| Syntax | Meaning |
|---|---|
$name | Variable interpolation |
${name} | Brace-delimited interpolation |
$(command) | Command substitution |
$((expr)) | Expression evaluation |
let name = "world"echo "hello $name" # hello worldecho "count: $((1 + 2))" # count: 3echo "${name}_suffix" # world_suffixSingle-quoted strings are literal — no interpolation occurs.
Comparison
Section titled “Comparison”== and != work on all types. <, >, <=, >= work only on numbers (int, float) and semver values. Using ordering operators on other types produces a type error.
Logical Operators
Section titled “Logical Operators”&&, ||, ! — standard boolean operators with short-circuit evaluation.
Lambdas
Section titled “Lambdas”Arrow syntax for anonymous functions:
- Explicit single-param:
x => x + 1 - Multi-param:
(acc, x) => acc + x - Implicit lambda: When a method like
maporfilterreceives a non-lambda expression, it is wrapped asa => <expr>. The implicit parameter is alwaysa:
[1, 2, 3].map(a + 10) # [11, 12, 13][1, 2, 3, 4].filter(a > 2) # [3, 4]`ls`.map("-> ${a}") # implicit lambda with string interpolationThe implicit a always shadows any outer variable named a within the lambda body.
Expression Statements
Section titled “Expression Statements”A parenthesized expression used as a statement evaluates the expression and outputs its value to stdout:
let x = 42(x) # outputs: 42(x * 2) # outputs: 84([1, 2, 3]) # outputs: [1, 2, 3]This is a shorthand for .writeln(stdout). The parentheses are required to distinguish an expression statement from a command invocation. Without them, a bare name in statement position resolves in the command namespace.