Anonymous user
Constrained genericity: Difference between revisions
no edit summary
No edit summary |
|||
Line 406:
<lang forth>include FMS-SI.f
include FMS-SILib.f
while▼
repeat false ;▼
:class Eatable
:m eat
;class
\ FoodBox is defined without
:class FoodBox
object-list eatable-types
:m init: eatable-types init: ;m
:m
if
else drop ." not an eatable type "
then ;m
▲ while eat
;class
Eatable aEatable
aEatable aFoodBox add: \ add the e1 object to the object-list
aFoodBox test \ => successful eat▼
:m eat cr ." successful eat " ;m ▼
;class
brick abrick \ create an object that is not eatable
▲FoodBox fb
▲successful eat
▲5 ' object fb1 fill: \ => not an eatable type
:class apple <super Eatable
;class
anapple aFoodBox add:
▲;class
aFoodBox test \ => successful eat successful eat
▲fb1 get test
▲successful eat
</lang>
|