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 # REPLWith -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'
2mzs 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'
3Line 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
3Notes 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.mzsOutput 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
matchedCheck, 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
| Flag | What it does | Default |
|---|---|---|
-t, --timeout <d> | time per run (0 — no limit) | 1s |
--steps <n> | step budget | 5000000 |
--mem <size> | memory: 64m, 1g | 64m |
--tasks <n> | async tasks at once | 64 |
--time | clock, time/date modules, now() | off |
--rand [seed] | rand(), uuid(), shuffle; seed for repeatability | off |
--no-io | no io module: no files, no stdin | io on |
--read-only | io only reads | |
--stats | steps, 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"'
okExit codes
| Code | When |
|---|---|
0 | success; a truthy value with --bool |
1 | compile or runtime error; a falsy value with --bool |
2 | bad command line |
3 | limit exceeded: time, steps, memory |
| any | exit(n) from the script |
sh
$ mzs -e 'exit(7)'; echo $?
7