Skip to content

Syntax

The language at a glance. help("syntax") shows the same in the REPL.

1
# decimals are exact
2
0.1 + 0.20.3
3
# dividing integers gives an exact fraction
4
7 / 23.5
5
# // divides and rounds down
6
7 // 23
7
# ** is power, and ^ is xor, not power
8
2 ** 101024
9
# hex and binary numbers stay in their base
10
0xff + 10x100
11
# units attach to numbers
12
60 km/h to m/s16.6667 m/s
13
# a number touching a name multiplies, with no space: variables win over units, and a space always means the unit
14
x = 3; [2x, 2pi, 2(x + 1), 3 m][6, 6.28319, 8, 3 m]
15
# a function and a space before a value calls it
16
sqrt 16 + sin 90 deg5
17
# percentages
18
80 + 15%92
19
# clock arithmetic: values that wrap around
20
10 mod 12 + 53 (mod 12)
21
# {...} in a string puts in a value
22
"2 + 2 = {2 + 2}""2 + 2 = 4"
23
# slices, where negative positions count from the end
24
"hello"[-3..]"llo"
25
# r"..." is a regular expression
26
"a1b22".find_all(r"\d+")["1", "22"]
27
# b"..." is raw bytes
28
b"\x7fELF"[1..].str"ELF"
29
# a..=b counts from a to b, a..b stops just before b
30
1..=5[1, 2, 3, 4, 5]
31
# maps hold values under names
32
{a: 1, b: 2}.b2
Example outputCtrl+Enter to run
1
# x.f(y) means f(x, y)
2
"a-b".split("-")["a", "b"]
3
# calls with no arguments need no parentheses
4
"hi".upper"HI"
5
# |> passes a value to a function
6
[3, 1, 2] |> sort[1, 2, 3]
7
# _ marks where the piped value goes
8
3.14159 |> round(_, 2)3.14
9
# |x| ... is a small function, a lambda
10
[1, 2, 3].map(|x| x * 10)[10, 20, 30]
11
# _ in parentheses or an argument is a lambda parameter
12
[1, 2, 3].map(_ * 10)[10, 20, 30]
13
# to converts a value to a unit, base, type or zone
14
255 to hex0xff
Example outputCtrl+Enter to run
1
# assignment, with no declaring needed
2
x = 5; x += 2; x7
3
# if gives a value, so it can be used anywhere
4
if 3 > 2 { "yes" } else { "no" }"yes"
5
# for loops over a range, list or other collection
6
t = 0; for i in 1..=4 { t += i }; t10
7
# unpack a list into names, _ skips an item
8
[a, [b, _]] = [1, [2, 3]]; a + b3
9
# while
10
n = 3; while n > 0 { n -= 1 }; n0
11
# fn defines a function
12
f = fn(x) { return x * 2 }; f(4)8
13
# f(x: type) = ... names a function, and the same name with other types adds an overload
14
size(x: int) = x; size(s: str) = s.len; [size(5), size("abc")][5, 3]
15
# comparisons chain, as in math
16
x = 5; 0 < x <= 10true
17
# # starts a comment that runs to the end of the line, and a new line or a semicolon ends a statement
Example outputCtrl+Enter to run

Command mode is for the file and program work you would otherwise switch to a terminal for.

One part is the built-in shortcuts: zil functions for things commonly done in a shell.

built-in commands
# list a folder, hidden files too
ls -la src
# → ls("src", long: true, all: true)
# lines with err, ignoring case
grep -i err app.log
# → grep(read_file("app.log"), "err", ignore_case: true)
# delete a folder and what's in it
rm -rf build
# → rm("build", recursive: true, force: true)
# a file's contents
cat a.txt
# → cat("a.txt")

Also, regular shell commands can be run with ! in front of them. The output is shown as it happens, and the result is the program’s exit code: 0 for success.

programs
# output shows as it happens
!git status
# → exec(["git", "status"], tty: true)
# interactive programs work too
!python
# → exec(["python"], tty: true)
# assigned, the output is captured instead
log = !git log --oneline -5
# → log = exec(["git", "log", "--oneline", "-5"])
# two programs, joined by a system pipe
!git log --oneline | head -3
# → exec(["git", "log", "--oneline"], ["head", "-3"], tty: true)

A few operators change meaning too.

operators
# | passes a result on, instead of bitwise or
ls src | grep rs
# → ls("src") |> grep("rs")
# > writes a file, instead of greater than
ls > files.txt
# → write_file(ls(), "files.txt")
# < feeds a file to a program
!sort < names.txt
# → exec(["sort"], stdin: read_bytes("names.txt"), tty: true)
# |> means the same as in zil, and goes back to it
ls src |> len
# → ls("src") |> len

help("shell") has the same in the REPL.

search functions whose name or description mentions a word, as text

search str
# → search("str")

read the contents of one or more files, as text joined into one string, or as bytes with the bytes flag

  • -b, --bytes give the contents as bytes, for files that aren’t text
read -b a.out
# → read("a.out", bytes: true)

read_file the contents of one or more files, joined into one string

cat a.txt b.txt
# → cat("a.txt", "b.txt")

ls what’s in a directory, as a table of name, type, size and modified

  • -a, --all include names starting with a dot, which are hidden otherwise
  • -l, --long accepted out of habit: the table always has the details
ls -la src
# → ls("src", long: true, all: true)

du the biggest files and folders directly in dir, largest first, with each folder counted for everything inside it

du src 5
# → du("src", "5")

rm delete files and empty directories

  • -r, --recursive also directories and everything in them
  • -f, --force skip paths that don’t exist instead of failing
  • -n, --dry-run list what would change, as a table of op, from and to, and change nothing
rm -rf build
# → rm("build", recursive: true, force: true)

mv move or rename files and directories

  • -n, --dry-run list what would change, as a table of op, from and to, and change nothing
mv *.log logs
# → mv(*glob("*.log").name, "logs")

cp copy files

  • -r, --recursive copy directories too
  • -n, --dry-run list what would change, as a table of op, from and to, and change nothing
cp -r src backup
# → cp("src", "backup", recursive: true)

mkdir create directories, along with any missing folders above them

  • -p, --parents accepted out of habit: missing folders above are always made
  • -n, --dry-run list what would change, as a table of op, from and to, and change nothing
mkdir -p out/logs
# → mkdir("out/logs", parents: true)

cwd the current directory, which relative paths start from

cwd
# → cwd()

pwd the current directory, the same as cwd() under the shell’s name

pwd
# → pwd()

cd change the current directory and return the new one

cd ../notes
# → cd("../notes")

grep the lines of a string, or items of a list, that contain pat

  • -i, --ignore-case ignore case
  • -v, --invert keep the lines that don’t match instead
  • -c, --count count the matches instead
grep -i err app.log
# → grep(read_file("app.log"), "err", ignore_case: true)

wc count lines, words and bytes, like the Unix wc tool

  • -l, --lines just the line count
  • -w, --words just the word count
  • -c, --bytes just the byte count
wc -l notes.txt
# → wc(read_file("notes.txt"), lines: true)

diff what changed from text a to b, line by line, or nil if nothing did

  • -p, --plain no colors, even on a terminal
  • -b, --bytes the command reads the files as bytes, for the bytes diff
  • -t, --table a table of changed lines instead of hunks
  • -B, --base for the bytes diff, the address the first byte is at
diff notes.txt notes2.txt
# → diff(read_file("notes.txt"), read_file("notes2.txt"))

hexdump bytes shown as a hex dump, like the xxd tool, or just n bytes around address at

  • -p, --plain no colors, even on a terminal
  • -t, --text only the text column, as one line
  • -B, --base the address the first byte is shown at, true for 0x400000
xxd a.out 0x1000
# → xxd(read_bytes("a.out"), "0x1000")

diff what changed from bytes a to b, by hex dump row, or nil if nothing did

  • -p, --plain no colors, even on a terminal
  • -t, --table a table of differing bytes instead of hunks
  • -B, --base the address the first byte is at, true for 0x400000
diff -b a.out b.out
# → diff(read_bytes("a.out"), read_bytes("b.out"))

strings the readable text hidden in binary data: every run of at least min printable characters, like the Unix tool

  • -t, --table a table of offset and text instead of a list
  • -B, --base the address the first byte is at, true for 0x400000
strings -t a.out
# → strings(read_bytes("a.out"), table: true)
# a command on its own runs with no arguments
ls
# → ls()
# * matches any part of a name
rm *.tmp
# → rm(*glob("*.tmp").name)
# put names with spaces in double quotes
cat "my file.txt"
# → cat("my file.txt")
# flags are letters that combine, -la is -l and -a, or names: --all is -a
# grep, wc, xxd and strings read the files you name, instead of taking text
# {expr} passes a zil value as one argument
rm {old}
# → rm(old)
# |> hands the result to a zil function
ls src |> len
# → ls("src") |> len
# with parentheses it's an ordinary call, not a command: files = ls("src")
# a variable with a command's name wins: after cat = 5, cat foo is no longer the cat command
# ! runs any program, showing its output
!git status
# → exec(["git", "status"], tty: true)
# on a line by itself, the result is the program's exit code: 0 for success
# assigned or piped, its output is captured
log = !git log --oneline -5
# → log = exec(["git", "log", "--oneline", "-5"])
# when output is captured, a program that fails is an error
# ! right before ( is still "not": !(x) means not x
# | feeds one command's result into the next
ls src | grep rs
# → ls("src") |> grep("rs")
# after |, any other name is a program
ls | sort
# → exec(["sort"], stdin: ls(), tty: true)
# between two programs, | is an ordinary system pipe
!git log --oneline | head -3
# → exec(["git", "log", "--oneline"], ["head", "-3"], tty: true)
# > writes a file, >> adds to the end of one
ls > files.txt
# → write_file(ls(), "files.txt")
# < feeds a file to a program as its input
!sort < names.txt
# → exec(["sort"], stdin: read_bytes("names.txt"), tty: true)
# 2> sends a program's errors to a file
!make 2> errors.txt
# → exec(["make"], stderr: "errors.txt", tty: true)
# help topic shows a help page, the same as help("topic")
# ? after a name shows its help: upper? is help upper, and now.moon_phase? is help moon_phase
# 'single quotes' aren't strings: write "...", or r"..." to keep backslashes as they are
# {a,b} brace expansion isn't supported: pass a list, {["a", "b"]}
# $VAR isn't a variable, since $ is for money like $5: write {env("VAR")}
# ls - l doesn't work: a flag's letters must touch its dash, -l
# ls | where(...) is an error, since after | a name means a program: use |> to hand the result to zil
# 2>&1 isn't supported: send error output to a file with 2> f

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