Skip to content

Prelude

Chloë Strainge edited this page Oct 14, 2026 · 1 revision

The implicit 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.

Collections

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 | ().

Numbers and text

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.

Shell helpers

  • path prints the current search path.
  • pushd and popd manage a directory stack.
  • dir_exists and file_exists test filesystem paths.
  • optional_env reads an optional environment value; get_env reflects bindings.
  • is_tty and is_pipe inspect standard output, useful for formatting output.
  • is_color indicates colored terminal output.
  • report_error reports captured error context.
  • any::print_properties prints 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

Clone this wiki locally