Skip to content

core

the basics: kinds of value, printing, converting between types, reading values from text, and help

Permissions: stdin

The basics every other module builds on: kinds of value, converting between them, printing, and help. Every value has a type, and nil means no value. Numbers come in three kinds. An int is a whole number of any size. A frac is an exact fraction, which is what dividing ints or typing a decimal like 0.1 gives you. A float is an approximate decimal, which is what roots and logs give you.

to followed by a type name converts to that type: "42" to int, 7/2 to float, "abc" to list.

Fracs show as decimals unless you ask for to frac.

Tags: conversion, parsing

  • print print the values on one line, separated by spaces
  • page print like print, but output too long for the terminal opens in a scrollable viewer
  • warn print a warning to stderr, dimmed in a terminal, and carry on
  • fail stop with an error message
  • assert stop with an error unless the condition is true
  • edit open a full-screen editor to type or paste text into, starting from text
  • type the name of a value’s type, like “int” or “quantity”
  • str convert to a string
  • int convert to an integer, dropping any fractional part
  • float convert to a float
  • frac show a number as a fraction, like 7/2, or as text rounded to the nearest 1/den, like “2 11/16 in”
  • bool whether a value counts as true in a test: everything does except nil and false, even 0 and “”
  • list convert to a list: a string’s characters, a map’s [key, value] pairs, a set’s items, a table’s rows as maps, or a copy of a list
  • desugar show what shell-style command lines mean: src with each one rewritten as the ordinary zil call it runs
  • parsed how src groups, with each operation that is an operand of another in parentheses
  • pretty a value as easy-to-read text
  • parse read a value written in zil syntax from text: a number, string, list, map or quantity
  • help help as text
  • search functions whose name or description mentions a word, as text
  • doc attach a description to your own function, shown by help
  • tip a random example to try, from help(“examples”) and help(“advanced”)
1
# nil: no value
2
nil
3
# bool: true or false
4
true
5
# int: a whole number, any size
6
0xff
7
# float: an approximate decimal
8
1.5e31500
9
# frac: an exact fraction
10
7/2 to frac7/2
11
# fn: a function
12
|x| x * 2<fn>
Example outputCtrl+Enter to run
1
# input holds everything piped into a script, as one string
2
# to str, to int, to float, to frac, to bool or to list
3
"42" to int42
Example outputCtrl+Enter to run
1
# long: separators, every decimal kept
2
pretty(1234567.891)"1,234,567.891"
3
# short: 3 digits and K, M, B or T
4
pretty(1234567, "short")"1.23M"
Example outputCtrl+Enter to run
print(*xs: any) -> nil

print the values on one line, separated by spaces

1
print("total:", 5 km)
Example outputCtrl+Enter to run

See also str

page(*xs: any) -> nil

print like print, but output too long for the terminal opens in a scrollable viewer

Arrow keys or the mouse wheel scroll, / searches and q quits

1
help("math") |> page
2
(1..200).map(|n| n ** 2).join("\n") |> page
Example outputCtrl+Enter to run

See also print, help

warn(msg: str) -> nil

print a warning to stderr, dimmed in a terminal, and carry on

1
warn("rates are stale")
Example outputCtrl+Enter to run

See also fail, assert, print

fail(msg: str) -> nil

stop with an error message

1
fail("no such planet")
Example outputCtrl+Enter to run

See also warn, assert

assert(cond: any, msg: str = “assertion failed”) -> nil

stop with an error unless the condition is true

1
assert(1 + 1 == 2)
2
assert(2 > 3, "two is not bigger")
Example outputCtrl+Enter to run

See also warn, fail

edit(text: str = “”) -> str

open a full-screen editor to type or paste text into, starting from text

Ctrl-S finishes and returns the text, and Esc cancels, which is an error

1
edit().lines.len
2
edit(paste()).upper
Example outputCtrl+Enter to run

See also page, paste

type(v: any) -> str

the name of a value’s type, like “int” or “quantity”

1
type(5 km)"quantity"
2
type("hi")"str"
3
type([1])"list"
Example outputCtrl+Enter to run

See also str, int, float

str(v: any) -> str

convert to a string

Floats keep every digit, unlike the rounded way they’re shown

1
str(1/3)"0.3333333333333333"
2
str(5 km)"5 km"
Example outputCtrl+Enter to run

See also int, float

int(v: num|str) -> int / int(s: str, base: int) -> int

convert to an integer, dropping any fractional part

Strings are read as numbers, in the given base if there is one, or by their prefix like 0x

1
int(3.9)3
2
"ff".int(16)0xff
3
"0b101".int0b101
Example outputCtrl+Enter to run

See also float, str

float(v: num|quantity|str) -> float

convert to a float

A quantity loses its unit

1
float("2.5")2.5
2
float(5 km)5
Example outputCtrl+Enter to run

See also int, str

frac(v: num|quantity, den?: int) -> frac|int|str

show a number as a fraction, like 7/2, or as text rounded to the nearest 1/den, like “2 11/16 in”

A float becomes the simplest fraction that’s within 1e-12 of it. With den the result is mixed text and keeps units

1
7/2 to frac7/2
2
1/3 + 1/6 to frac1/2
3
0.75.frac3/4
4
2.7 in to frac(16)"2 11/16 in"
Example outputCtrl+Enter to run

See also float, mixed_frac

bool(v: any) -> bool

whether a value counts as true in a test: everything does except nil and false, even 0 and “”

1
bool(0)true
2
nil to boolfalse
Example outputCtrl+Enter to run

See also str

list(v: str|list|map|set|table) -> list

convert to a list: a string’s characters, a map’s [key, value] pairs, a set’s items, a table’s rows as maps, or a copy of a list

1
list("abc")["a", "b", "c"]
2
"abc" to list["a", "b", "c"]
3
{a: 1, b: 2}.list[["a", 1], ["b", 2]]
Example outputCtrl+Enter to run

See also chars, parse

desugar(src: str) -> str

show what shell-style command lines mean: src with each one rewritten as the ordinary zil call it runs

help(“shell”) explains command lines

1
desugar("grep -iv err")"grep(\"err\", ignore_case: true, invert: true)"
2
desugar("diff a.txt b.txt")"diff(read_file(\"a.txt\"), read_file(\"b.txt\"))"
Example outputCtrl+Enter to run

See also help, parse, parsed

parsed(src: str) -> str

how src groups, with each operation that is an operand of another in parentheses

Shows how units and operators bind without running anything

1
parsed("5 m/2 s")"(5 m) / (2 s)"
2
parsed("1 + 2 * 3 ** 2")"1 + (2 * (3 ** 2))"
Example outputCtrl+Enter to run

See also desugar, parse

pretty(v: any, style: str = “long”) -> str

a value as easy-to-read text

The “long” style spells things out, and “short” keeps it compact. The help page for each type shows how it looks

1
pretty(1234567)"1,234,567"
2
pretty(1234567, "short")"1.23M"
Example outputCtrl+Enter to run

See also str, commas, simplify, parts, format

parse(s: str) -> any

read a value written in zil syntax from text: a number, string, list, map or quantity

It never runs code, so it’s safe on untrusted text

1
"[1, 2.5, 0xff]".parse[1, 2.5, 0xff]
2
"5 km".parse to m5000 m
Example outputCtrl+Enter to run

Tags: parsing

See also str, nums

help(topic?: any) -> str

help as text

The topic can be a function, a module (“trig” or “math.trig”), a unit, or any value to list the functions for its type

1
help(upper)
2
help("math.trig")
3
help(today)
4
help("text") |> grep("case")
Example outputCtrl+Enter to run
search(word: str) -> str

functions whose name or description mentions a word, as text

Unlike help, it searches even when the word names a function or page: search str lists the functions about strings

1
search("sorting") |> grep("desc")
Example outputCtrl+Enter to run

As a command:

search str
# → search("str")

See also help

doc(f: fn, desc: str, examples?: list, tags?: list) -> nil

attach a description to your own function, shown by help

It applies to every overload of f’s name. Examples are strings of code that help runs, and tags are plain labels.

1
area(r) = 3.14 * r^2; doc(area, "area of a circle", examples: ["area(2)"])
Example outputCtrl+Enter to run

See also help

tip() -> str

a random example to try, from help(“examples”) and help(“advanced”)

1
tip()
Example outputCtrl+Enter to run

See also help

1
# what type a value is
2
type(5 km)"quantity"
3
# parse values from text
4
parse("[1, 2, 5 km]")[1, 2, 5 km]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.