Skip to content

Expressions and Operators

Operators +, -, *, /, % work on int and float. Integer division truncates. Mixed int/float operations promote to float.

10 + 3 # 13
10 / 3 # 3 (int division truncates)
10.0 / 3 # 3.333... (mixed promotes to float)
10 % 3 # 1 (modulo)

The ~ operator (D-style) concatenates strings:

let full = "hello" ~ " " ~ "world"
let path = HOME ~ "/docs"

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.

SyntaxMeaning
$nameVariable interpolation
${name}Brace-delimited interpolation
$(command)Command substitution
$((expr))Expression evaluation
let name = "world"
echo "hello $name" # hello world
echo "count: $((1 + 2))" # count: 3
echo "${name}_suffix" # world_suffix

Single-quoted strings are literal — no interpolation occurs.

== and != work on all types. <, >, <=, >= work only on numbers (int, float) and semver values. Using ordering operators on other types produces a type error.

&&, ||, ! — standard boolean operators with short-circuit evaluation.

Arrow syntax for anonymous functions:

  • Explicit single-param: x => x + 1
  • Multi-param: (acc, x) => acc + x
  • Implicit lambda: When a method like map or filter receives a non-lambda expression, it is wrapped as a => <expr>. The implicit parameter is always a:
[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 interpolation

The implicit a always shadows any outer variable named a within the lambda body.

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.