LEARN VOID / 02
Variables & constants
Give values a name.
Complete program for the synchronous entry adapter. The result below is the returned integer.
const unit_price: i32 = 3
func entry(quantity: i32) -> i32:
var total = quantity * unit_price
total += 2
const amount_due = total
return amount_dueInput 5Expected result 17
Infer local types
var total = quantity * unit_price creates a mutable integer binding. With quantity 5 and unit price 3, the subtotal is 15. The compiler infers i32 from the typed operands.
Update an existing value
total += 2 adds a fixed delivery fee, bringing the amount due to 17. Assignment updates an existing binding; it does not silently declare another variable.
Make readonly intent visible
The module-level unit_price is a typed compile-time constant. The local amount_due is a readonly binding computed during execution. Neither binding can be reassigned. For managed objects, readonly access restricts that view; another mutable alias can still change the same object.