LEARN VOID / DATA & BEHAVIOR
Properties
Put accessor logic behind ordinary field-style access.
Complete program for the synchronous entry adapter. The result below is the returned integer.
value struct rectangle:
width: i32
height: i32
property (shape rectangle) area: i32:
get:
return shape.width * shape.height
func entry(extension: i32) -> i32:
var garden = rectangle(width = 4, height = 3)
garden.width += extension
return garden.areaInput 5Expected result 27
Compute area from current fields
A rectangle stores width and height; its area getter computes their product. There is no cached area field to update when dimensions change.
Read after a change
The garden begins with width four and height three. Extending the width by input 5 gives width nine; garden.area then reads 27. With no extension, the area is 12.
Keep access intentional
The property has no setter, so callers cannot assign to garden.area. A setter can be defined when assignment has a clear meaning. Getters cannot mutate their receiver; fallible operations use explicit methods.