Repository navigation
Syntax Reference
This is a navigation reference, not a substitute for the worked explanations. Placeholders below describe forms rather than executable programs.
| 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 | 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].
| 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
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use