Repository navigation
Prelude
The prelude makes common functions and extension methods available without an explicit import. Its interface is copied into each new module after initialization. It can be a file or a directory package.
Arrays have empty, sum, min, max, unique, append, prepend, push,
push_many, pop, and peek helpers. Native methods also include count, sort,
reverse, zip, and next_item. reverse returns a new array.
The stack operations use the front of the array. push changes the receiver;
pop removes and returns its first item, or returns () when empty.
let $tasks = ["pack", "ship"]
$tasks.push "label"
echo $tasks.pop
echo $tasks.peek
echo $tasks.reverse...
label
pack
ship pack
Receiver-dependent annotations let methods preserve element types. A typed
[String] stack accepts Strings, and pop returns String | ().
min, max, and sum accept variadic numeric input. Arrays provide corresponding
methods. Strings provide count, pad, strip_prefix, and strip_suffix, alongside
native trimming, splitting, searching, and replacement methods.
echo (sum 4 8 12)
echo ("bay".pad 6 ".")
echo ("log:ready".strip_prefix "log:")
24
bay...
ready
Array::from_string splits colon-delimited text; Array::to_string joins it.
Both preserve empty entries, supporting typed environment bindings.
-
pathprints the current search path. -
pushdandpopdmanage a directory stack. -
dir_existsandfile_existstest filesystem paths. -
optional_envreads an optional environment value;get_envreflects bindings. -
is_ttyandis_pipeinspect standard output, useful for formatting output. -
is_colorindicates colored terminal output. -
report_errorreports captured error context. -
any::print_propertiesprints an object's or represented type's interface.
Ordinary names can be shadowed. Use ::name to request an external program when
a prelude helper has the same name. See Commands.
Related: Arrays · Strings · Environment · Reflection
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