Thank you Elizabeth, but I was hoping to find some method like the more simple
one I used on forward references (LMI metacompiler) it generates much more less
code and for using the name directly instead of the number it's more bug free.
regards,
Nestor Closa
"Elizabeth D. Rather" ha escrito:
> 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.
----------------------------------------------------------------------
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 Wed Mar 27 2002 - 07:02:54 PST
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.