Gotchas
Variables and Primitive Types
Working with primitive types in Luma is straightforward, but there are a few things to keep in mind. These aren’t bugs - just design choices that can surprise you if you’re coming from other languages.
int vs float
- Luma does not silently mix
intandfloat. - If you add them together, the compiler enforces explicit or implicit coercion.
a: int = 5
b: float = 2.5
// result must be float
avg: float = (a + b) / 2 // `a` is coerced to floatThis is by design: you always know what type the result will be.
byte is not str
- A
byteis a single numeric value (0–255). - A
stris a sequence of characters. - Assigning one to the other doesn’t work directly.
b: byte = 65
text: str = "A"
// This won’t work:
// text = b
// because `b` is a number, not a string.If you want to display a byte as text, use string interpolation:
print("Byte as char: ${b}")nil and optional types
- Only optional types (
?int,?str, etc.) can be set tonil. - Regular
int,str,bool, etc. must always have a value.
maybe: ?int = nil // allowed
count: int = nil // errorBoolean logic
&&,||, and!only work withbool.- They do not auto-convert numbers (
0,1) to boolean like some languages do.
flag: bool = true
if flag && !false {
print("ok")
}Gotchas with Optionals
Optional types are powerful, but they come with a few important caveats:
- Only optionals can be
nil
count: int = nil // not allowed
maybe: ?int = nil // allowed- Comparisons require care
If you compare an optional to a non-optional value, the optional must not benil.
x: ?int = nil
if x == 5 { // ❌ unsafe if x is nil
print("five")
}- Operations on
niloptionals will fail
Arithmetic and string operations assume a value is present. Always check fornilfirst, or use conversion with defaults.
s: str = "abc"
n: int = s.to_int(0) // returns default 0 if conversion fails- Printing optionals shows
nilliterally
This is intentional for clarity, but may surprise newcomers.
x: ?str = nil
print(x) // prints "nil"More Gotchas Coming…
This page is open for more tips and common pitfalls. As Luma evolves, we’ll extend this section with clarifications around variables, types, and expressions.
Last updated on