\ -*- mode: forth -*-
\ $Id: methcall.bigforth,v 1.2 2001/06/24 23:22:53 doug Exp $
\ http://www.bagley.org/~doug/shootout/
\ from Bernd Paysan:
\ I'm using oof.fs here (native OOF for bigforth), code using one of
\ the other OO Forth extensions will look different.
0. argc @ 1- arg >number 2drop drop constant NUM
include oof.fb
object class Toggle
cell var state
public:
method activate
method value
how:
: init state ! ;
: value state @ ;
: activate state @ invert state ! ;
class;
Toggle class NthToggle
cell var count-max
cell var counter
how:
: init
super init count-max ! 0 counter ! ;
: activate
1 counter +!
counter @ count-max @ >= if
state @ invert state !
0 counter !
then ;
class;
: flag.
if ." true" else ." false" then cr ;
: mainloop
true NUM 0 ?do
drop dup toggle with activate value endwith
loop
flag. drop ;
: main
true Toggle new mainloop
3 true NthToggle new mainloop ;
main bye