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
| Need | Use |
|---|---|
| Print a value | println(value); f"value={value}" |
| Read an optional command-line argument | ARGV.get(index, fallback) |
| Loop over a sequence | for (item in range(start, end)) { ... } |
| Work with a list | len(list), push(list, item), sort(list), join(list, separator) |
| Read optional map data | record.get("key", fallback), record.has("key") |
| Convert structured data | json_parse(text), json_stringify(value) |
| Check an assumption | require(condition, "what should be true") |
| Read and write files | read_file(path), write_file(path, text), read_lines(path) |
| Run a process without a shell | system(["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.