Index: library/xotcl/tests/slottest.xotcl =================================================================== diff -u -r65e384fc5b5fa044c63075f03756da88d316249f -r364a9eda329acd7d20173a4165d71394d3061aae --- library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision 65e384fc5b5fa044c63075f03756da88d316249f) +++ library/xotcl/tests/slottest.xotcl (.../slottest.xotcl) (revision 364a9eda329acd7d20173a4165d71394d3061aae) @@ -452,16 +452,14 @@ ? {p2 salary} 1009 Person slots { - Attribute create sex -type "sex" -convert true { - :public method type=sex {name value} { + Attribute create sex -type "sex" -convert true -proc type=sex {name value} { #puts stderr "[self] slot specific converter" switch -glob $value { m* {return m} f* {return f} default {error "expected sex but got $value"} } } - } } Person p3 -sex male ? {p3 sex} m @@ -522,13 +520,11 @@ nx::Test case assign-via-slots Class create A -slots { - Attribute create foo -default 1 { - :public method assign {domain var value} { - if {$value < 0 || $value > 99} { - error "$value is not in the range of 0 .. 99" - } - $domain set $var $value + Attribute create foo -default 1 -proc assign {domain var value} { + if {$value < 0 || $value > 99} { + error "$value is not in the range of 0 .. 99" } + $domain set $var $value } } @@ -618,6 +614,25 @@ ? {catch {p2 name add BOOM!}} 1 ? {p2 name} "John Doe" +# +# 3) -proc inline statements upon Attribute creation +# (as found in the tutorial) +# + +Class create AA -slots { + Attribute foo -default 1 -proc assign {domain var value} { + if {$value < 0 || $value > 99} { + error "$value is not in the range of 0 .. 99" + } + $domain set $var $value + } +} + +AA create aa1 +? {aa1 foo 10} 10 +? {aa1 foo} 10 +? {catch {aa1 foo -1}} 1 + exit #puts [Person array get __defaults]