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


Groups > comp.lang.forth > #44726

Re: Is WHILE allowed within DO .. LOOP ?

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Is WHILE allowed within DO .. LOOP ?
Date 2016-01-09 16:51 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2016Jan9.175121@mips.complang.tuwien.ac.at> (permalink)
References (4 earlier) <568e645f$0$23758$e4fe514c@news.xs4all.nl> <2016Jan7.143356@mips.complang.tuwien.ac.at> <J5qdncTosM7boxLLnZ2dnUU7-KudnZ2d@supernews.com> <2016Jan8.111957@mips.complang.tuwien.ac.at> <n6p8dq$e15$1@dont-email.me>

Show all headers | View raw


Bernd Paysan <bernd.paysan@gmx.de> writes:
>Anton Ertl wrote:
>
>> Here the WHILE jumps to the THEN in the other counted loop.  But given
>> that this should work in Gforth and, to my knowledge, has not been
>> used, it will probably not be a frequent construct.
>
>Works, has been used:
>
>: capscomp  ( c_addr1 u c_addr2 -- n )
> swap bounds
> ?DO  dup c@ I c@ <>
>     IF  dup c@ toupper I c@ toupper =
>     ELSE  true  THEN  WHILE  1+  LOOP  drop 0
> ELSE  c@ toupper I c@ toupper - unloop  THEN  sgn ;

This contains only one DO...LOOP, so it is not a case of using WHILE
to jump from one DO...LOOP into another one.

This word is crying out for cleanup, however, and the WHILE out of the
DO..LOOP is pretty low on the priority list.  Well, let me have a try:

The stack effect looks suspicious, but I'll ignore that for now.

: capscomp  ( c_addr1 u c_addr2 -- -1|0|1 )
  swap bounds ?do
    dup c@ toupper i c@ toupper - dup if
      sgn unloop exit then
    1+ loop
  drop 0 ;

(untested) Simpler and cleaner.  Not sure how slow TOUPPER is, it
might also be faster.  It certainly saves a bit by not applying SGN to
0.

- 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

Is WHILE allowed within DO .. LOOP ? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-06 16:28 +0000
  Re: Is WHILE allowed within DO .. LOOP ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-01-06 17:20 +0000
  Is WHILE allowed within DO .. LOOP ? JennyB <jennybrien@googlemail.com> - 2016-01-06 09:24 -0800
    Re: Is WHILE allowed within DO .. LOOP ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-01-06 16:06 -0600
      Re: Is WHILE allowed within DO .. LOOP ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-07 08:36 +0000
        Re: Is WHILE allowed within DO .. LOOP ? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-07 13:13 +0000
          Re: Is WHILE allowed within DO .. LOOP ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-07 13:33 +0000
            Re: Is WHILE allowed within DO .. LOOP ? "Elizabeth D. Rather" <erather@forth.com> - 2016-01-07 18:42 -1000
              Re: Is WHILE allowed within DO .. LOOP ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-08 10:19 +0000
                Re: Is WHILE allowed within DO .. LOOP ? Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-08 22:09 +0100
                Re: Is WHILE allowed within DO .. LOOP ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-09 16:51 +0000
                Re: Is WHILE allowed within DO .. LOOP ? Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-09 19:49 +0100
                Re: Is WHILE allowed within DO .. LOOP ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-10 15:44 +0000
              Re: Is WHILE allowed within DO .. LOOP ? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-08 11:22 +0000
    Re: Is WHILE allowed within DO .. LOOP ? hughaguilar96@gmail.com - 2016-01-06 22:33 -0800
      Re: Is WHILE allowed within DO .. LOOP ? Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-01-06 22:47 -0800
  Re: Is WHILE allowed within DO .. LOOP ? hughaguilar96@gmail.com - 2016-01-11 19:46 -0800
    Re: Is WHILE allowed within DO .. LOOP ? Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-01-11 22:37 -0800

csiph-web