Syntax Overview

Luma’s syntax is designed to be minimal, readable, and modern - drawing inspiration from languages like Python, Go, and Kotlin, but keeping a consistent and predictable structure.

This chapter gives you a high-level overview of how Luma looks and feels.

Variable Declarations

name: str = "Alice"
age: int = 30
active: bool = true

Optional types

nickname: ?str = nil
points: ?int = score.to_int()

The ? prefix marks a type as nullable.

Types

Type Description
int Whole number
float Decimal number
bool true or false
str Unicode string
byte 8-bit value (0x00 - 0xFF)
[T] List of type T
{K:V} Map/dictionary
{T} Set of type T
?T Optional/nullable of T

Type Introspection

s: str = "hello"
print(s.type())          // str
print(s.is_type("str"))  // true

Walk (like for)

nums: [int] = [1, 2, 3]

nums.walk(i, v) -> {
  print("${i}: ${v}")
}

nums.walk(v) -> print(v)

Conversion

s: str = "123"
i: int = s.to_int(0)       // 123
f: float = s.to_float(0.0) // 123.0
b: bool = s.to_bool(false) // true if non-empty

maybe: ?int = s.to_int()   // 123 or nil

Interpolated Strings

name: str = "Luma"
print("Hello ${name}!")

Ranges

(0..3)       // 0, 1, 2
(1..=5)      // 1, 2, 3, 4, 5

(1..=5).walk(n) -> print(n)

Conditionals

if age >= 18 {
  print("Adult")
} else {
  print("Minor")
}

Functions

fn greet(name: str) -> str {
  return "Hi ${name}"
}

print(greet("Luma"))

Collections

list: [int] = [1, 2, 3]
set: {int} = {1, 2, 3}
map: {str: int} = {"a": 1, "b": 2}

Null-safe Access

Optional types return nil if unset. You can safely check:

if val != nil {
  print(val)
}

Built-in Functions

Function Description
.type() Returns type name of value
.is_type(t) Checks value type
.to_int() Converts to int (optional)
.to_float() Converts to float (optional)
.to_bool() Converts to bool (optional)
.to_str() Converts to string
.to_byte() Converts to byte (e.g., 0x48)

Minimal & Consistent

Luma’s goal is not to be clever - it’s to be clear. The syntax:

  • Avoids excessive punctuation
  • Uses consistent patterns (name: type = value)
  • Makes nullable, iterable, and callable elements explicit

If you can read it, you can reason about it.

Last updated on