Quick cheat sheet

Keep this page open while learning. A semicolon ends each statement; braces group statements. Names are created by assignment. Values include null (no value), booleans (true or false), numbers, strings (text), lists (ordered values), and maps (values stored under named keys).

Everyday syntax

name = ARGV.get(0, "world");
println(f"Hello, {name}!");

fn square(n) { return n * n; }
total = 0;
for (n in range(1, 4)) {
  if (n == 2) { continue; }
  total = total + square(n);
}
require(total == 10, "unexpected total");

person = {name: "Ada", age: 36};
names = [person.name, "Lin"];
println(join(names, ", "));

Common built-ins

NeedUse
Print a valueprintln(value); f"value={value}"
Read an optional command-line argumentARGV.get(index, fallback)
Loop over a sequencefor (item in range(start, end)) { ... }
Work with a listlen(list), push(list, item), sort(list), join(list, separator)
Read optional map datarecord.get("key", fallback), record.has("key")
Convert structured datajson_parse(text), json_stringify(value)
Check an assumptionrequire(condition, "what should be true")
Read and write filesread_file(path), write_file(path, text), read_lines(path)
Run a process without a shellsystem(["program", "argument"])

List indexes start at zero. A missing map key or list index is an error; use get with a fallback when data may be absent. system receives an argument list, so shell quoting and shell expansion do not apply.

For the full command list and native host blocks, see the user guide. For common mistakes with actual error text, see Troubleshooting.

Back to the first lesson · Continue to control flow