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


Groups > comp.lang.forth > #45373

Re: The extended Eaker-Pelc CASE as general control structure

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: The extended Eaker-Pelc CASE as general control structure
Date 2016-02-08 18:10 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2016Feb8.191003@mips.complang.tuwien.ac.at> (permalink)
References <2016Feb6.191548@mips.complang.tuwien.ac.at> <3c828c96-5a9a-4e36-affe-d948d2c1a5d7@googlegroups.com> <2016Feb8.135932@mips.complang.tuwien.ac.at> <f1d17606-6474-4027-a5d1-c8f4ae799f4c@googlegroups.com>

Show all headers | View raw


JennyB <jennybrien@googlemail.com> writes:
>On Monday, 8 February 2016 14:23:47 UTC, Anton Ertl  wrote:
>> Also, if we are going for representing conditions by using
>> control-flow, I think we should also eliminate the IF at the end and
>> the flag that controls it.  Maybe something along the lines of
>>=20
>> MULTI-COND
>>   cond1 -COND
>>   cond2 +COND
>>   cond3 +COND
>>   code-when-all-satisfied
>> OTHERWISE
>>   code-when-one-cond-failed
>> THEN
>>=20
>I don't see there how you would distinguish between the last condition and =
>the code that follows it.

If all of the conds match, you fall through to
CODE-WHEN-ALL-SATISFIED.  OTHERWISE is like ELSE, but it resolves all
the CONDs since MULTI-COND (or maybe there should just be a FIRST-COND
instead).

>It seems simpler to think of the CASE block as re=
>turning a unified flag.  I had a lot of trouble getting my head round ANDIF=
> and ORIF until I realised that there is no need to test further after a tr=
>ue OR or a false AND.

Yes.  Now, the general case for compiling any arbitrarily deeply
nested conditional expression with short-circuit operators is to
realize that you always only have two branch targets: one for true,
and one for false.  If you have

condition IF ( A ) ... ELSE ( B ) ... THEN

then the general target for true is A and for FALSE is B.  No need to
push flags on the stack across a longer distance.  When you have just
a sequence of ANDIFs or ORIFs, you only need to consider these two
targets.  When you have some nested conditional, you may get different
true and false targets for sub-expressions.

One advantage of this approach would be that it reduces the stack
depth at run-time (at the cost of increased compile-time control-flow
stack depth).  Disadvantages are a potential for more branch
mispredictions and the testing disadvantage I mentioned.  I don't know
of a syntax and implementation for the general case, however.

>> CONTINUE does not make it clear that it concludes the OF/IF part; it
>> certainly does not in C.
>
>My mistake then, but I don't see how it could be otherwise.

Yes, in Forth it's the only way that makes sense, but it still has a
different meaning than in C, so I chose a different name.

>Possibly not. Mine allows the familiar loop structures to be extended by ad=
>ding extra IF .. CONTINUE of IF ... BREAK clauses and only needs a surround=
>ing CASE if there more than one BREAKs.

I don't consider that an advantage.  Then someone wants to add another
case, and needs to change the whole loop.  And when reading the code,
it produces more variation for no gain.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/

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


Thread

The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-06 18:15 +0000
  Re: The extended Eaker-Pelc CASE as general control structure JennyB <jennybrien@googlemail.com> - 2016-02-07 03:57 -0800
    Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 12:59 +0000
      Re: The extended Eaker-Pelc CASE as general control structure JennyB <jennybrien@googlemail.com> - 2016-02-08 09:48 -0800
        Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 18:10 +0000
          Re: The extended Eaker-Pelc CASE as general control structure JennyB <jennybrien@googlemail.com> - 2016-02-09 14:02 -0800
            Short-circuit evaluation (was: The extended Eaker-Pelc CASE ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-10 16:10 +0000
  Re: The extended Eaker-Pelc CASE as general control structure "WJ" <w_a_x_man@yahoo.com> - 2016-02-07 14:32 +0000
  Re: The extended Eaker-Pelc CASE as general control structure "WJ" <w_a_x_man@yahoo.com> - 2016-02-07 14:53 +0000
    Re: The extended Eaker-Pelc CASE as general control structure Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-07 15:56 +0000
      Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-07 18:11 +0000
        Re: The extended Eaker-Pelc CASE as general control structure "HAA" <someone@microsoft.com> - 2016-02-08 12:04 +1100
          Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-08 10:29 +0000
            Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 11:00 +0000
              Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-08 12:28 +0000
                Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 15:26 +0000
                Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-08 16:16 +0000
                Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 16:37 +0000
                Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 16:21 +0000
            Re: The extended Eaker-Pelc CASE as general control structure "HAA" <someone@microsoft.com> - 2016-02-11 21:12 +1100
              Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-11 10:46 +0000
      Re: The extended Eaker-Pelc CASE as general control structure JennyB <jennybrien@googlemail.com> - 2016-02-07 12:33 -0800
        Re: The extended Eaker-Pelc CASE as general control structure stephen@mpeforth.com (Stephen Pelc) - 2016-02-08 10:38 +0000
  Re: The extended Eaker-Pelc CASE as general control structure "HAA" <someone@microsoft.com> - 2016-02-08 12:07 +1100
    Re: The extended Eaker-Pelc CASE as general control structure anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 11:11 +0000
      Re: The extended Eaker-Pelc CASE as general control structure Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-08 14:49 +0000
      Re: The extended Eaker-Pelc CASE as general control structure "HAA" <someone@microsoft.com> - 2016-02-09 20:31 +1100
        Re: The extended Eaker-Pelc CASE as general control structure hughaguilar96@gmail.com - 2016-02-09 12:38 -0800
      Re: The extended Eaker-Pelc CASE as general control structure "WJ" <w_a_x_man@yahoo.com> - 2016-02-11 14:23 +0000
        Re: The extended Eaker-Pelc CASE as general control structure "WJ" <w_a_x_man@yahoo.com> - 2016-02-11 19:45 +0000

csiph-web