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
second

Statements and lines

Every statement is on its own line. A statement is one of:

StatementExample
a variable declarationcount: int = 0
an assignmentcount = count + 1
an ifif count > 0 { ... }
a trytry err { ... }
a throwthrow error(100, "message")
a function callprint(count)

Two statements on one line are an error:

print("a") print("b")     // error: expected end of line after the statement

An 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:

big

Comments

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 statement

Output:

hi

Names

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 = 0

Reserved 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:

KindNames
typesint float byte bool str error file json date time datetime buffer tcp http
valuestrue false nil null self
functionsprint prompt flag file free convert len remove has union intersect diff error
groups of functionscrypto (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

KindExamplesSee
integer42 0 0xFFTypes
float1.5 0.25 1.5e3Types
booltrue falseTypes
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