Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #44655
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Is WHILE allowed within DO .. LOOP ? |
| Date | 2016-01-07 08:36 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2016Jan7.093605@mips.complang.tuwien.ac.at> (permalink) |
| References | <568d4097$0$23799$e4fe514c@news.xs4all.nl> <f99450de-28cc-40aa-96b9-573a98220d33@googlegroups.com> <bvWdnQQARaR5EhDLnZ2dnUU7-audnZ2d@supernews.com> |
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>JennyB <jennybrien@googlemail.com> wrote:
>
>> This is not meant to be portable. It only works if do-sys happens to
>> be the right size.
>>
>> It's also needlessly complex. The cleaner (and portable) way to do
>> this sort of thing is:
>>
>> DO
>> IF ... UNLOOP EXIT THEN
>> ...
>> LOOP
>> ...
>>
>> ;
>
>The caller usually needs to know whether the loop was exited early.
>So, the above would likely be
>
>: barf ( - t)
> do
> if ... unloop true ( we found something) exit then
> ...
> loop
> ...
>
> false ( we didn't find anything) ;
>
>and the caller would have to do
>
> barf if found-action else not-found-action then
>
>I hate passing flags around like that. I prefer
>
> do ...
> while
> ...
> loop
> not-found-action
> else
> found-action unloop
> then
Or you can write it in standard Forth as
do
... if ... found-action unloop exit then
... loop
not-found-action
In any case, the word that spawned this discussion actually returns
true or false, so the technique you defend here does not prevent that.
It also and has no control flow join in the end, so it could be
converted into standard Forth without any drawback. Makes me wonder
why it was written in this way in the first place.
- 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
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