# Syntax reference
This is a navigation reference, not a substitute for the worked explanations.
Placeholders below describe forms rather than executable programs.
## Declarations
| `let $name[: Type] [= expression]` | [Variables](Variables-and-Scope) |
| `let ($a, $b) = expression` | Exact-length destructuring in [Variables](Variables-and-Scope) |
| `let _ = expression` | Evaluate and discard |
| `let export $name = expression` | [Environment](Environment) |
| `let type $name = Type` | Convert an existing environment binding |
| `fn name($arg: Type): Result { ... }` | [Functions](Functions-and-Calls) |
| `fn ($arg: Type): Result { ... }` | [Closures](Closures-and-Function-Types) |
| `fn Type::method(...): Result { ... }` | [Methods](Methods-and-Properties) |
| `type Name = Type` | [Distinct named types](Named-Types-and-Unions) |
| `struct Name { field: Type }` | [Structs](Structs) |
| `enum Name { First, Second }` | [Enums](Enums) |
| `error struct Name { ... }` | [Errors](Errors-and-Cleanup) |
| `alias name = command default_argument` | [Commands](Commands-and-Exit-Status) |
| `pub declaration` | [Module visibility](Modules) |
| `import path::{ Name } [when expression]` | [Modules](Modules) |
| `[when expression] declaration` | [Conditional code](Conditional-Code) |
An omitted function result is `()`, including methods and anonymous functions.
Write `: any` explicitly for a dynamic result. See [function contracts](Functions-and-Calls).
## Type forms
| `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
| `+ - * / %` | [Arithmetic](Numbers-and-Logic) |
| `== != < <= > >=` | Equality and numeric ordering |
| `! && \|\|` | Boolean conversion and short-circuit logic |
| `a..b`, `a..=b` | [Ranges](Ranges-and-Iteration) |
| `$array[index]`, `$array[start..end]` | [Arrays](Arrays) |
| `$map[key]` | [Hash maps](Hash-Maps) |
| `$value.member`, `$value.::field` | [Methods and raw fields](Methods-and-Properties) |
| `Type(value)` | [Explicit conversion](Conversions) |
| `if condition { a } else { b }` | [Control flow](Control-Flow) |
| `match value { pattern => { result } }` | [Matching](Match-and-Type-Guards) |
| `source \| stage` | [Pipelines](Pipelines) |
| `source format:\|:Type stage` | [Pipeline conversion](Pipeline-Formats) |
| Aligned `\-` and vertical `\|` guides | [Pipeline splits](Pipeline-Splits) |
| `command -> target` | [Redirection](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](Pipeline-Splits#share-tabbed-scripts).
---
Related: [Language map](Language-Map) · [Language basics](Language-Basics) · [Quick start](Quick-Start)