On Mar 14, 9:43 am, "Ed" <nos...@[EMAIL PROTECTED]
> wrote:
> <m_l...@[EMAIL PROTECTED]
> wrote in
messagenews:632fcc9e-c13c-40bf-baa0-5a329b59c0b0@[EMAIL PROTECTED]
> > 1) The words CASE and ENDCASE are already taken: please find other
> > names. CASE is not necessarily an immediate 0.
>
> The case statement is intended to be compatible with the
> ANS version. No names need to change.
>
> The code provided is for demonstration only. It shows how
> such a case statement *might* be implemented. Implementors
> will need to adapt it to the requirements of their system.
>
> To clarify what this case statement can do:
>
> CASE
> ... OF ... ENDOF
> COND ... EQUAL ... RANGE WHEN ... ELSE
> ... DUP IF DROP ... ELSE
> ... ( no match )
> ENDCASE
>
> OF ... ENDOF isn't really needed anymore but is retained
> for ANS compatibility. I didn't include code for it in the
> demo but it is easily added -
>
> : ENDOF postpone else ; immediate
> : OF postpone dup postpone if postpone drop ; immediate
>
> > 2) Do you have an implementation that uses tables? You could. You
> > could switch to interpretation state between COND and WHEN.
>
> I hadn't considered that. Do you have an example?
>
> > 3) You cannot rely on the size of orig and dest being 1 or 2 cells:
> > $ gforth
> > Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc.
>
> > 0 value orig-size ok
> > : foo [ depth to orig-size ] if [ depth orig-size - to orig-size ]
> > then ; ok
> > orig-size . 3 ok
> > 0 value dest-size ok
> > : bar [ depth to dest-size ] begin [ depth dest-size - to dest-size ]
> > until ; ok
> > dest-size . 3 ok
>
> > In fact, it, at least in theory, may be 0 cells on the data stack
> > (and N cells on some other stack).
>
> Yes, that's why I include the disclaimer:
>
> \ This code is not ****table. It makes assumptions about the
> \ control flow stack which may not be applicable to your forth.
>
> To make the demo run on Gforth, use:
>
> : WHEN
> postpone else >r >r >r thens r> r> r> postpone drop ;
immediate
I've named one of the two conditional exits WHEN
http://wiki.forthfreak.net/index.cgi?TerseControlStructures
, I don't
know is this is common usage though:
: example1 full? unless eat-lunch ;
: example2 hungry? when eat-lunch ;


|