Variables & Constants
Luma offers a simple yet expressive system for declaring variables and constants. The syntax is concise and readable, focusing on clarity and type safety.
Variable Declaration
You define a variable using this pattern:
name: str = "Alice"
age: int = 30
price: float = 9.99
active: bool = true- The syntax is always:
name: type = value - Types are explicit for clarity and safety.
- All variables are mutable by default.
Constants with lock
To declare an immutable constant, prefix it with lock. This ensures the variable cannot be reassigned after its declaration.
lock PI: float = 3.14
lock WELCOME: str = "Hello"Attempting to reassign PI will result in a compile-time error.
Optional Variables
Use ? to mark a variable as nullable (i.e., it may be nil):
email: ?str = nil
score: ?int = "42".to_int()Nullable types are useful when a value may or may not exist.
Type Inference (Not yet implemented)
Luma may support type inference in the future, but currently all variable types must be explicitly declared.
Examples
name: str = "Luma"
count: int = 42
price: float = 19.95
valid: bool = false
lock VERSION: str = "1.0"
maybeAge: ?int = nilBest Practices
- Use
lockfor constants like configuration or math values. - Always choose the most accurate type (e.g.
floatvsint). - Prefer
?typeover using rawnilwhen nullability is intended.
Last updated on