\ -*- mode: forth -*-
\ $Id: methcall.gforth,v 1.2 2001/06/24 23:22:53 doug Exp $
\ http://www.bagley.org/~doug/shootout/
\ from Anton Ertl:
\ I'm using objects.fs here, code using one of the other OO Forth
\ extensions will look different.
warnings off \ don't complain about redefining catch, state, value
0. argc @ 1- arg >number 2drop drop constant NUM
require objects.fs
object class
selector activate
selector value
cell% inst-var state
m:
state ! ;m
overrides construct
m:
state @ ;m
overrides value
m:
state @ invert state !
this ;m
overrides activate
end-class Toggle
Toggle class
cell% inst-var count-max
cell% inst-var counter
m:
this [parent] construct
count-max !
0 counter ! ;m
overrides construct
m:
1 counter +!
counter @ count-max @ >= if
state @ invert state !
0 counter !
endif
this ;m
overrides activate
end-class NthToggle
: flag.
if ." true" else ." false" endif cr ;
: mainloop
true swap heap-new true NUM 0 ?do
drop dup activate value
loop
flag. drop ;
: main
Toggle mainloop
3 NthToggle mainloop ;
main bye