![]() | ||
| Home | SwiftX Archive | SwiftForth Archive | |

There are many approaches. Here's one:
10 CONSTANT #STATES
CREATE STATES #STATES CELLS ALLOT
VARIABLE MYSTATE
: STATE ( n -- ) MYSTATE @ 1- \ Provide for 1-relative
indexing
0 MAX #STATES MIN \ Clip to within bounds
CELLS STATES + @EXECUTE ; \ Perform function
: Main ( -- )
1 MYSTATE !
BEGIN
KEY STATE
AGAIN ;
: State1 ( event -- )
somecode1 IF
2 MYSTATE !
THEN :
' State1 STATES 0 CELLS + ! \ Note 0-relative index here
[etc.]
You might be able to avoid the bounds clipping by ensuring you write
all the code and you'll never set an illegal state. Also, you might prefer
to do everything zero-relative, and avoid the 1-
Cheers,
Elizabeth
At 05:44 PM 3/26/02 -0300, Nestor D. Closa wrote:
>How can you write states in forth without forward references ?
>
>VARIABLE 'MyState
>
>: State1 ( event -- )
> somecode1
> IF
> ['] State2 'MyState !
> THEN ;
>
>: State2 ( event -- )
> somecode2
> IF
> ['] State3 'MyState !
> THEN ;
>
>: State3 ( event -- )
> somecode3
> IF
> ['] State1 'MyState !
> THEN ;
>
>: Main ( -- )
> ['] State1 'MyState !
> BEGIN
> KEY 'MyState @EXECUTE
> AGAIN ;
>
>
>Nestor Closa
>
>
>
>----------------------------------------------------------------------
>swiftx_at_forth.com The SwiftX programming discussion email list
>To unsubscribe, send subject "unsubscribe swiftx" to listar_at_forth.com
>For help with listar commands, send subject "help" to listar_at_forth.com
>Archives are located at http://www.forth.com/swiftx -- check them out!
>----------------------------------------------------------------------
>THIS LIST IS NOT FOR BUG REPORTS! Send bug reports to support_at_forth.com.
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454
Hawthorne, CA 90250
http://www.forth.com
"Forth-based products and Services for real-time
applications since 1973."
==================================================
----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe swiftx" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/swiftx -- check them out!
----------------------------------------------------------------------
THIS LIST IS NOT FOR BUG REPORTS! Send bug reports to support_at_forth.com.
Received on Tue Mar 26 2002 - 13:07:25 PST
This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:23 PST