Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Variables and Bindings

AetherShell supports several forms for declaring and binding variables, from explicit let declarations to concise shorthand syntax.

Let Bindings

The standard way to declare a variable:

let name = "AetherShell"
let version = 3
let features = ["typed", "pipelines", "AI"]

Variables are immutable by default. Attempting to reassign an immutable variable produces an error:

let x = 10
x = 20    # Error: Cannot reassign immutable variable 'x'. Use 'let mut x' to make it mutable.

Mutable Variables

Use mut to allow reassignment:

let mut counter = 0
counter = counter + 1    # OK
counter = 42             # OK

Or with shorthand:

mut counter = 0
counter = counter + 1

Shorthand Syntax

AetherShell offers shorter forms for common patterns:

# These are all equivalent:
let x = 10
x = 10       # Inferred let
x := 10      # Walrus-style binding

Public Variables

Variables can be marked public for export from modules:

pub let API_URL = "https://api.example.com"
pub let VERSION = "1.0.0"

Public variables are accessible when the module is imported.

Type Annotations

Optional type annotations can be added to bindings:

let name: String = "hello"
let count: Int = 42

Type annotations are parsed but currently used for documentation purposes. The type inference engine (typecheck.rs) handles type validation.

Scoping Rules

AetherShell uses a flat environment model:

  • All variables share a single scope
  • Lambda parameters are temporarily bound during execution and restored after
  • There are no block-level scopes or shadowing in the traditional sense
  • Variables are visible once declared and remain available for the rest of the session
let x = 10
let f = fn(x) => x * 2    # Lambda parameter 'x' temporarily shadows outer 'x'
f(5)                        # => 10
x                           # => 10 (outer x unchanged)

Environment Variables

Shell environment variables are accessible and can be set:

# Access environment variable
let home = $HOME

# Set environment variable
export PATH = "/usr/local/bin:${$PATH}"

Assignment vs. Declaration

SyntaxMeaning
let x = exprImmutable declaration
let mut x = exprMutable declaration
x = exprShorthand immutable declaration (or reassign if mutable)
x := exprShorthand immutable declaration
mut x = exprShorthand mutable declaration
pub let x = exprPublic immutable declaration