Basics
A program
A Luma program is a text file (UTF-8) with the extension .luma. It runs from the first line to the last, one statement at a time.
print("first")
print("second")Output:
first
secondStatements and lines
Every statement is on its own line. A statement is one of:
| Statement | Example |
|---|---|
| a variable declaration | count: int = 0 |
| an assignment | count = count + 1 |
an if | if count > 0 { ... } |
a try | try err { ... } |
a throw | throw error(100, "message") |
| a function call | print(count) |
Two statements on one line are an error:
print("a") print("b") // error: expected end of line after the statementAn expression on its own, such as 1 + 2, is not a statement. It would do nothing, so Luma reports it as an error.
Long lines
Inside parentheses ( ) and square brackets [ ], an expression may continue on the next lines:
total: int = (1 +
2 +
3)
days: [str] = [
"Mon",
"Tue",
]
print(total)
print(days)Output:
6
["Mon", "Tue"]Blocks
Curly braces { } group statements into a block, for example the body of an if. Inside a block, statements are on separate lines as usual. A short block may be written on one line:
x: int = 3
if x > 1 { print("big") }Output:
bigComments
A comment starts with // and runs to the end of the line. Comments are ignored. For longer comments, write several // lines; there are no /* */ comments. See Comments.
// This whole line is a comment
print("hi") // a comment after a statementOutput:
hiNames
Variable names are made of letters, digits and underscores, and don’t start with a digit. Only the English letters a–z and A–Z are allowed. Upper and lower case are different: count and Count are two names.
count: int = 1
max_value: int = 100
_tmp2: int = 0Reserved words
Luma has only seventeen reserved words:
if else match while try throw skip stop fn return import pub lock obj trait defer assert(walk is not reserved: it is written after a dot, nums.walk(n).)
Built-in names
These names are predefined. You can’t use them as variable names:
| Kind | Names |
|---|---|
| types | int float byte bool str error file json date time datetime buffer tcp http |
| values | true false nil null self |
| functions | print prompt flag file free convert len remove has union intersect diff error |
| groups of functions | crypto (crypto.sha256(...), see crypto), random (random.int(1, 6), see random), env (env.get("PORT", 8080), see env), uuid (uuid.v7(), see uuid) |
Values you can write directly
| Kind | Examples | See |
|---|---|---|
| integer | 42 0 0xFF | Types |
| float | 1.5 0.25 1.5e3 | Types |
| bool | true false | Types |
| string | "Hello" "two\nlines" "Hi ${name}" | Types, Interpolated strings |
| list | [1, 2, 3] [] | Lists |
| map | {"a": 1, "b": 2} {} | Maps |
| set | {1, 2, 3} {} | Sets |