LEARN VOID / DATA & BEHAVIOR
Properties
Put accessor logic behind ordinary field-style access.
value struct rectangle:
width: i32
height: i32
property (shape rectangle) area: i32:
get:
return shape.width * shape.height
func entry(width: i32) -> i32:
var panel = rectangle(width = width, height = 3)
return panel.areaInput 5Expected result 15
Compute a value from fields
A rectangle stores its width and height. Its area property multiplies those two fields when read, so there is no separate area field to keep synchronized.
Read it like a field
panel.area calls the property getter. With width 5 and height 3, the result is 15. The example uses a value struct and a single property.
Choose whether assignment makes sense
This property has no setter, so callers cannot assign to panel.area. A property can also define a setter when writing it has a clear meaning. Getters cannot mutate their receiver.