Still feeling inspired, here's my state machine _dialect_ and a general
purpose _queue_ for REBOL. First, %Queue.r:

Queue!: func [/Initial Size [integer!]][
 all [not Initial Size: 10]
 make object! [
  In: func ['Word [word!] Value /Arg2 Value2][
   append _Queue Word
   append/only _Queue reduce Value
   if Arg2 [append/only _Queue reduce Value2]
   ]
  _Queue: make block! Size
  Out: func [][
   do _Queue
   Clear
   ]
  Clear: func [][
   system/words/clear _Queue
   ]
  ]
 ]


Then %State.r:

State!: func [][
 make object! [
  _State: no
  State: func [][_State]
  Start: func ['Initial [word!]][
   _State: Initial
   ]
  Stop: func [][_State: no]
  Run!: func [][
   while [_State][
    try [do State true]
    ]
   ]
  Goto: func ['Next [word!]][
   _State: Next
   ]
  Dialect: function [Dialect [block!]][Locals][
   Locals: make block! 10
   foreach Item Dialect [
    if set-word? :Item [
     Item: mold :Item
     replace Item ":" ""
     Item: to-word Item
     if not found? find Locals Item [
      append Locals Item
      ]
     ]
    ]
   use Locals bind/copy Dialect '_State
   ]
  ]
 ]

State: State!

do %Queue.r

State/Dialect [
 Queue: Queue!
 then: now/time
 na: 0
 a: [
  na: na + 1
  Queue/In print ["na:" na]
  Goto b
  ]
 nb: 0
 b: [
  nb: nb + 1
  Queue/In print ["nb:" nb]
  either nb < 10 [
   Goto a
   ][
   Stop
   ]
  ]
 Start a
 Run!
 Queue/In print (now/time - then)
 Queue/Out
 na ; return the counter.
 ]

They're also attached.

Andrew Martin
Who's sure that 'parse-block will improve this...
ICQ: 26227169
[EMAIL PROTECTED]
http://members.xoom.com/AndrewMartin/
-><-


Queue.r

State.r

Reply via email to