Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Miser's CAS...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 17 Topic 3814 of 4287
Post > Topic >>

Re: Miser's CASE

by "Mark W. Humphries" <mwh@[EMAIL PROTECTED] > Mar 13, 2008 at 07:41 PM

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 ;
 




 17 Posts in Topic:
Miser's CASE
"Ed" <nospam  2008-03-08 17:44:31 
Re: Miser's CASE
m_l_g3@[EMAIL PROTECTED]   2008-03-12 11:14:44 
Re: Miser's CASE
"Ed" <nospam  2008-03-14 12:43:47 
Re: Miser's CASE
"Ed" <nospam  2008-03-18 10:51:51 
Re: Miser's CASE
Coos Haak <chforth@[EM  2008-03-18 01:06:41 
Re: Miser's CASE
"Mark W. Humphries&q  2008-03-13 19:41:47 
Re: Miser's CASE
"Ed" <nospam  2008-03-15 11:21:21 
Re: Miser's CASE
Alex McDonald <blog@[E  2008-03-15 05:33:52 
Re: Miser's CASE
"Ed" <nospam  2008-03-16 16:15:33 
Re: Miser's CASE
"Mark W. Humphries&q  2008-03-15 09:45:59 
Re: Miser's CASE
John Doty <jpd@[EMAIL   2008-03-15 10:52:05 
Re: Miser's CASE
Bruce McFarling <agila  2008-03-15 13:33:37 
Re: Miser's CASE
Bruce McFarling <agila  2008-03-15 22:56:19 
Re: Miser's CASE
"Ed" <nospam  2008-03-16 18:48:04 
Re: Miser's CASE
Bruce McFarling <agila  2008-03-16 13:00:29 
Re: Miser's CASE
"Ed" <nospam  2008-03-18 12:33:40 
Re: Miser's CASE
Bruce McFarling <agila  2008-03-18 09:05:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 3:10:04 CDT 2008.