Skip to content

Command line ​

Running ​

sh
mzs script.mzs arg1 arg2     # arguments after the file go to $ARGV
mzs -e '"hello".upper'       # HELLO
cat script.mzs | mzs -       # program from stdin
mzs                          # REPL

With -e the value of the last expression is printed (unless nil), with a file nothing is; -p always prints, --no-print never does. Several -e are joined line by line.

sh
$ mzs hello.mzs world        # hello.mzs: println("hi ${$ARGV[0]}")
hi world
$ mzs -e 'x = 1' -e 'x + 1'
2

mzs flags go before the file name: everything after it is the script's arguments.

Data from stdin ​

When the program comes from -e or a file, stdin is data: io.lines, io.stdin, input(). --in file reads the data from a file.

sh
$ printf 'alpha 1\nbeta 2\ngamma 3\n' > data.txt
$ cat data.txt | mzs -e 'include io; io.lines.len'
3

Line mode: -n and -l ​

-n runs the program for each line, the line is in $_. -l does the same and prints the result unless it is nil. $… variables live across lines, locals do not.

sh
$ cat data.txt | mzs -n -e '$_.split(" ")[0]'
alpha
beta
gamma
$ mzs -l --in data.txt -e '$_.split(" ")[1].int * 10'
10
20
30
$ cat data.txt | mzs -n -e '$n = ($n ?? 0) + 1'
1
2
3

Notes that must stay out of the data stream go to stderr with eprintln.

Host variables ​

sh
$ mzs -v name=Ann -e '"hello, ${$name}"'           # a string
hello, Ann
$ mzs --vars '{"n": 3, "xs": [1,2]}' -e '$n + $xs.len'   # JSON keeps types
5
$ mzs --vars-file vars.json script.mzs

Output format ​

sh
$ mzs --json -e '{a: [1, nil]}'
{"a":[1,null]}
$ mzs --bool -e '"yes" in ["yes", "yep"]' && echo matched   # exit code instead of output
matched

Check, format, test ​

sh
$ mzs --check script.mzs     # compile only: errors and warnings
script.mzs: ok
$ mzs fmt script.mzs         # print the formatted code
$ mzs fmt -w src/            # rewrite files in place
$ mzs fmt -l .               # list unformatted files
$ mzs test                   # run every *_test.mzs
ok   trim
FAIL sum
     expected 4, got 3 (demo_test.mzs:3:27)

Capabilities and limits ​

FlagWhat it doesDefault
-t, --timeout <d>time per run (0 — no limit)1s
--steps <n>step budget5000000
--mem <size>memory: 64m, 1g64m
--tasks <n>async tasks at once64
--timeclock, time/date modules, now()off
--rand [seed]rand(), uuid(), shuffle; seed for repeatabilityoff
--no-iono io module: no files, no stdinio on
--read-onlyio only reads
--statssteps, time and memory to stderr
sh
$ mzs -e 'while true {}'
-e:1:1: limit: step budget exceeded (5000000 steps)
$ mzs -t 5 -e 'sleep(2); "ok"'
ok

Exit codes ​

CodeWhen
0success; a truthy value with --bool
1compile or runtime error; a falsy value with --bool
2bad command line
3limit exceeded: time, steps, memory
anyexit(n) from the script
sh
$ mzs -e 'exit(7)'; echo $?
7