Example 1 (associated getter):
Test: class {
value: Int {
get { return 2 }
set (x) {
if (this value == 2)
"two" println()
else
"not two, but: %i" printfln(this value)
}
}
init: func
}
x := Test new()
x value = 10
should print "two" but prints "not two, but: 0".
Example 2 (setter calling itself):
Same here. But:
Test: class {
value: Int {
get { return 2 }
set (x) {
"old value=%i" printfln(this value)
this value = x
}
}
init: func
}
x := Test new()
x value = 2
x value = 3
x value = 4
should always print "old value=2" but prints
old value=0
old value=2
old value=3
Example 1 (associated getter):
should print "two" but prints "not two, but: 0".
Example 2 (setter calling itself):
Same here. But:
should always print "old value=2" but prints