LEARN VOID / DATA & BEHAVIOR
Composition
Build a type from smaller pieces of behavior.
Complete program for the synchronous entry adapter. The result below is the returned integer.
value struct position:
x: i32
func (location position) advance(steps: i32):
location.x += steps
struct cursor:
using location: position
func entry(steps: i32) -> i32:
var pointer = cursor(location = position(x = 10))
pointer.advance(steps)
return pointer.xBuild from a component
The cursor stores a position as location. using location: position promotes accessible members, so the program can call pointer.advance and read pointer.x without manually forwarding them.
Follow the contained value
The component starts at ten and advances by the input. With 5 steps, both pointer.x and pointer.location.x refer to the updated coordinate 15. The promoted call still operates on the cursor’s contained position.
Keep the component’s semantics
Composition does not change ownership. Copying a value component copies its value storage; a managed component retains shared reference identity. The ordinary cursor itself is managed. Promotion also preserves visibility, receiver-effect and readonly checks.
Ask about a type relationship
marker has location is a compile-time Boolean: marker directly stores a using location component. The typed if-expression returns one integer from either branch and requires an else. This relationship is true, so the result is one; the adapter input is unused.
value struct location:
x: i32
struct marker:
using position: location
func entry(input: i32) -> i32:
return if marker has location:
1
else:
0A struct target tests exact directly stored using components, including inherited storage. Ordinary fields, recursive components and self identity do not count. An interface target tests structural method conformance. Both branches still type-check: has is neither reflection nor conditional compilation.