Skip to content

Introduction ​

mzs is a small embeddable scripting language written in Go. It is used for bot scripts in the Morze studio, one-liners in the terminal, and programs a host runs in a sandbox.

Five rules ​

Everything is an expression. The value of the last expression is the result of a script, a function, a closure. return is optional.

mzs
fn grade(n) { if n >= 90 { "A" } else { "B" } }
grade(95)  # → "A"

{ … } is a closure unless it is a dict. {a: 1} and {} are dicts, anything else is a block of code.

mzs
[1, 2, 3].map { it * 2 }  # → [2,4,6]
{a: 1}.keys  # → ["a"]

[ … ] is always an array. JSON pastes into code as is.

mzs
order = {"id": 7, "items": [{"sku": "A1", "qty": 2}]}
order["items"][0]["qty"]  # → 2

x.f(y) is exactly f(x, y). There are no separate methods and functions: one namespace, your own fn included.

mzs
fn shout(s) { s.upper + "!" }
"hello".shout  # → "HELLO!"
len("world") == "world".len  # → true

match instead of an else if chain.

mzs
fn kind(x) {
  match x {
    0 -> "zero"
    in 1..9 -> "digit"
    else -> "many"
  }
}
[0, 5, 42].map { kind(it) }  # → ["zero","digit","many"]

First program ​

mzs
text = "the quick brown fox jumps over the lazy dog the fox"
words = text.split(" ")
top = words.tally.array.max_by { it[1] }
println("words: ${words.len}, most frequent: ${top[0]} ×${top[1]}")
text
words: 11, most frequent: the ×3

Surprises ​

mzs
7 / 2  # → 3
7.0 / 2  # → 3.5
"2".int + 1  # → 3
"привет".len  # → 6
[].bool  # → true
  • int / int is integer division.
  • Types are never converted implicitly: "2" + 1 is an error.
  • Length and indices are in characters, not bytes.
  • Only nil and false are falsy.

Keywords ​

fn if else match while for in break next return try ensure include export true false nil

next is continue.