Repository navigation
Arrays
An array keeps ordered values. Indexes start at zero. Without an annotation its items can have different types; an annotation supplies an element contract.
let $stops: [String] = ["harbor", "museum", "garden", "station"]
let $afternoon = $stops[1..3]
echo $afternoon...
echo $stops[..=1]...
museum garden
harbor museum
.. excludes the end and ..= includes it. Omitted bounds use the array edges.
Bounds must be nonnegative and in range; an exclusive end can equal the length.
Reversed bounds produce an empty slice after bounds are checked.
let $original = [[1, 2]]
let $copy = $original
$copy[0][0] = 9
echo $original[0]...
echo $copy[0]...
1 2
9 2
Indexed writes replace existing positions. They do not grow the array. Reading a slice makes a copy; assigning through a slice is not supported.
Spread with ... to insert elements into another literal or supply arguments.
An unexpanded array remains one function argument:
let $middle = [2, 3]
let $all = [1, $middle..., 4]
echo $all...
echo $all.reverse...
1 2 3 4
4 3 2 1
[String] means a homogeneous array type in annotations. As a value expression,
a single bare type entry also creates a typed empty array. [(String)] instead
stores the String type object. Multiple entries are ordinary values.
[Integer, String] in an annotation describes exactly two positions.
[Integer,] is a one-position shape; [Integer] allows any length. Fixed shapes
are useful for destructuring and iterator results.
.value_type returns a Type value. Explicit annotations are retained on empty
arrays; otherwise homogeneous contents infer a type and mixed/unknown contents
use any.
- Native:
count,sort,reverse,zip,next_item,properties. - Prelude:
empty,sum,min,max,unique,append,prepend,push,push_many,pop,peek.
Numeric sort uses the exact mixed-number comparison
used by <, <=, >, and >=.
reverse, sort, append, and prepend return new arrays. Stack methods mutate
$self; push adds at the front, push_many pushes in supplied order, and pop
removes the front item. min, max, pop, and peek can return () when empty.
zip stops at the shorter input. Sorting accepts mutually comparable items and
does not execute references stored as String values.
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