Values and Bindings
Kelvra keeps the expression model small on purpose. The language supports typed
integers and floats, booleans, null, strings, grouping, arithmetic,
comparison, logical operators, and bitwise operators. See
Built-in Types and Casts for the
numeric families, literal suffixes, and as conversions.
Expressions
Section titled “Expressions”print((2 + 3) * 4)print(10 > 3)print(!false && true)print(7 & 3)print(1 << 4)The current operator surface includes:
- arithmetic:
+,-,*,/ - comparison and equality:
>,>=,<,<=,==,!= - logical operators:
!,&&,|| - bitwise operators:
&,|,^,~,<<,>>
var and const
Section titled “var and const”Local bindings can be written with explicit types or with local inference.
var count i32 = 10var message = "kelvra"const answer = 42const enabled bool = trueUse const when the binding should not be reassigned. Use var when mutation
is part of the design.
Type inference
Section titled “Type inference”Inference works well for local values whose initializer already makes the type obvious.
fn buildCounter() Counter { var counter = Counter() return counter}Current repo guidance is stricter for public APIs and ambiguous cases:
- function parameters still need explicit types
- exported APIs should stay explicit
- locals inferred from
void-producing expressions are rejected
Assignment and updates
Section titled “Assignment and updates”Bindings and index/member targets support assignment and compound assignment.
var total i32 = 10total += 5total <<= 1print(total)Update operators are also available:
var i i32 = 0i++++iprint(i)Bindings are lexical. Inner scopes can read outer names, and nested functions can capture them.
fn outer() i32 { var x i32 = 10
fn inner() i32 { return x + 1 }
return inner()}Read Functions and Closures for the closure-specific behavior.