Skip to content

Syntax Reference

Chloë Strainge edited this page Oct 15, 2026 · 3 revisions

Syntax reference

This is a navigation reference, not a substitute for the worked explanations. Placeholders below describe forms rather than executable programs.

Declarations

Form Guide
let $name[: Type] [= expression] Variables
let ($a, $b) = expression Exact-length destructuring in Variables
let _ = expression Evaluate and discard
let export $name = expression Environment
let type $name = Type Convert an existing environment binding
fn name($arg: Type): Result { ... } Functions
fn ($arg: Type): Result { ... } Closures
fn Type::method(...): Result { ... } Methods
type Name = Type Distinct named types
struct Name { field: Type } Structs
enum Name { First, Second } Enums
error struct Name { ... } Errors
alias name = command default_argument Commands
pub declaration Module visibility
import path::{ Name } [when expression] Modules
[when expression] declaration Conditional code

An omitted function result is (), including methods and anonymous functions. Write : any explicitly for a dynamic result. See function contracts.

Type forms

Type Meaning
Integer, Float, Boolean, String Scalar types
Number Integer or Float constraint
any General value type
() Unit / no value
T | U, T | () Union; optional union
[T] Array of T
[K: V] Hash with key K, value V
[T, U] Fixed-shaped item/row type
fn(T, U): R First-class function prototype
$self.value_type, $self.key_type Dependent collection method annotations

[Integer] in value position creates a typed empty array. [(Integer)] contains one type object. Hash typed-empty syntax is [String: Integer].

Expressions and operators

Forms Guide
+ - * / % Arithmetic
== != < <= > >= Equality and numeric ordering
! && || Boolean conversion and short-circuit logic
a..b, a..=b Ranges
$array[index], $array[start..end] Arrays
$map[key] Hash maps
$value.member, $value.::field Methods and raw fields
Type(value) Explicit conversion
if condition { a } else { b } Control flow
match value { pattern => { result } } Matching
source | stage Pipelines
source format:|:Type stage Pipeline conversion
Aligned \- and vertical | guides Pipeline splits
command -> target Redirection
::command External command lookup

Arithmetic multiplication/division/remainder bind before addition/subtraction; comparisons bind before &&, and && before ||. Pipeline stages associate left to right. Use parentheses to state grouping explicitly, especially around invocations inside an expression. Parentheses enclosing a function prototype control whether a union belongs to its return type or to the function value.

Statements can be separated by newlines or ;. A backslash continues a line. # begins a comment. Double-quoted Strings interpolate; single-quoted Strings remain literal. $array... spreads arguments/items; bare $ means pipeline input.

#tab-size N in the file header selects tab stops for that source. Precedence is file directive, explicit --tab-width N, $SHELLY_TAB_SIZE, then 4. See split alignment and tabs.


Related: Language map · Language basics · Quick start

Clone this wiki locally