\ -*- mode: forth -*-
\ $Id: objinst.bigforth,v 1.3 2001/06/25 20:54:09 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 swap 0 ?do
drop dup toggle with activate value endwith dup flag.
loop
drop ;
: main
true Toggle new 5 mainloop
NUM 0 ?do
true Toggle new toggle with dispose endwith \ like the C version
loop
cr
3 true NthToggle new 8 mainloop
NUM 0 ?do
3 true NthToggle new toggle with dispose endwith \ like the C version
loop ;
main bye