Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #9168

Re: CASE comparison values

From Aleksej Saushev <asau@inbox.ru>
Newsgroups comp.lang.forth
Subject Re: CASE comparison values
Date 2012-01-23 22:23 +0400
Organization A noiseless patient Spider
Message-ID <87ehuq46ru.fsf@inbox.ru> (permalink)
References <dedb18b4-3a6e-4012-b0bd-ff017e5bdd1e@a8g2000pbi.googlegroups.com> <8f3f21b9-757d-4454-95a6-dc88dc19af04@pt5g2000pbb.googlegroups.com>

Show all headers | View raw


Brad <hwfwguy@gmail.com> writes:

> The standard (dpans94.pdf) gives a simple example implementation (page
> 135):
>
> 0 CONSTANT CASE IMMEDIATE  ( init count of OFs )
>
> : OF  ( #of -- orig #of+1 / x -- )
>    1+    ( count OFs )
>    >R    ( move off the stack in case the control-flow )
>          ( stack is the data stack. )
>    POSTPONE OVER  POSTPONE = ( copy and test case value)
>    POSTPONE IF    ( add orig to control flow stack )
>    POSTPONE DROP  ( discards case value if = )
>    R>             ( we can bring count back now )
> ; IMMEDIATE

"over = if drop" is useful factor itself.

Personally, I find using "... case: ... case;" in many cases more readable
than standard "case ... of ... endof endcase.

: case:  postpone over postpone = postpone if postpone drop ; immediate
: case;  postpone exit postpone then ; immediate
: otherwise:  postpone drop ; immediate

These even allow nesting. Even though you have to watch for it yourself,
rules are simple enough.


-- 
HE CE3OH...

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

CASE comparison values Percy <percival.andrews@gmail.com> - 2012-01-23 05:32 -0800
  Re: CASE comparison values Brad <hwfwguy@gmail.com> - 2012-01-23 07:57 -0800
    Re: CASE comparison values Aleksej Saushev <asau@inbox.ru> - 2012-01-23 22:23 +0400
  Re: CASE comparison values JennyB <jennybrien@googlemail.com> - 2012-01-23 09:11 -0800
    Re: CASE comparison values stephenXXX@mpeforth.com (Stephen Pelc) - 2012-01-23 18:38 +0000
      Re: CASE comparison values alberto pasquale <alberto@hal-pc.org> - 2012-01-23 11:42 -0800
        Re: CASE comparison values Percy <percival.andrews@gmail.com> - 2012-01-23 14:58 -0800
          Re: CASE comparison values "Elizabeth D. Rather" <erather@forth.com> - 2012-01-23 13:41 -1000
          Re: CASE comparison values Brad <hwfwguy@gmail.com> - 2012-01-23 19:20 -0800
        Re: CASE comparison values "Peter Knaggs" <pjk@bcs.org.uk> - 2012-01-24 10:03 +0000

csiph-web