Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #133936
| From | dxf <dxforth@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: DO..LOOP and stack shuffling |
| Date | 2025-07-03 13:59 +1000 |
| Organization | i2pn2 (i2pn.org) |
| Message-ID | <1a695310e64de0b2d7589a73bfa9b2c35d2323a0@i2pn2.org> (permalink) |
| References | (1 earlier) <84d259e0f1d6210d84c7840af5d51f4ebdd71ed4@i2pn2.org> <c9158c200102c2e508f8ef11deecdc27@www.novabbs.com> <248abae6393c59470a015b195642e266@www.novabbs.com> <2025Jun28.194649@mips.complang.tuwien.ac.at> <nnd$212756f0$3238b797@8662155c42ec7025> |
On 1/07/2025 9:53 pm, Hans Bezemer wrote: > On 28-06-2025 19:46, Anton Ertl wrote: >> And while DO has an obvious shortcoming (partially addressed by ?DO), >> I have found that variations on ?DO..LOOP are quite helpful in keeping >> the number of items on the data stack manageable. They mean that I >> don't have to deal with the index and limit in the loop body, and that >> they are also out of the way, so I don't have to think about them in >> the loop body. And when I need the loop index, "I" gives it to me, >> like an automatically-defined local. > > Wow.. I learned this about 20 years ago from the creator of the FIG Forth editor. You find it in the "c" and "delete" commands. > > And yeah - you're completely right: it works like a "read-only" local. > The TORS can be used as a "r/w" local - with the additional penalty of a R> >R pair (like 2OS comes with a SWAP SWAP penalty). BTW, knowing this gives you hints on how to organize your stacks. > > The DO..LOOP advantages - nah, not really. E.g. an "address" loop can be done like (a n = address count): > > OVER SWAP /ELEMENT * + >R > BEGIN DUP R@ < WHILE ( ..) /ELEMENT + REPEAT R> DROP DROP > > No need for BOUNDS DO..LOOP .. > FOR..NEXT is even easier: > > >R BEGIN R@ 0> WHILE ( ..) R> 1- >R REPEAT R> DROP > > So for a lot of applications, I don't really need DO..LOOP and its deeply flawed implementation. And since R@ and I are synonyms, I can even use I if I prefer I! :) > ... When I need a 'counted' loop DO LOOP is always shorter/faster than a BEGIN REPEAT. I provide a couple FOR NEXTs in the distribution for the curious however they provide no practical advantage (same footprint and in the case of CP/M even slower). So for me the issue was settled long ago. I imagine it's the same for most forthers even if their circumstances mean they've opted differently.
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar
OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-23 05:09 +0000
Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-24 23:28 +1000
Re: OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-26 17:27 +0000
Re: OOS approach revisited minforth@gmx.net (minforth) - 2025-06-27 02:16 +0000
Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-27 17:29 +1000
Re: OOS approach revisited minforth <minforth@gmx.net> - 2025-06-27 11:49 +0200
Re: OOS approach revisited zbigniew2011@gmail.com (LIT) - 2025-06-27 16:55 +0000
Re: OOS approach revisited albert@spenarnc.xs4all.nl - 2025-06-27 20:15 +0200
Re: OOS approach revisited minforth <minforth@gmx.net> - 2025-06-27 22:35 +0200
Re: OOS approach revisited albert@spenarnc.xs4all.nl - 2025-06-28 11:34 +0200
Re: OOS approach revisited Stephen Pelc <stephen@vfxforth.com> - 2025-06-28 09:37 +0000
Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-28 12:03 +1000
LOOP (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 10:23 +0000
Re: LOOP (was: OOS approach revisited) albert@spenarnc.xs4all.nl - 2025-06-28 14:26 +0200
Re: LOOP dxf <dxforth@gmail.com> - 2025-06-28 22:41 +1000
Re: LOOP sean@conman.org - 2025-06-28 20:04 +0000
Re: LOOP anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 21:01 +0000
Re: LOOP minforth@gmx.net (minforth) - 2025-07-03 19:33 +0000
Re: LOOP Gerry Jackson <do-not-use@swldwa.uk> - 2025-07-07 07:54 +0100
Re: LOOP minforth <minforth@gmx.net> - 2025-07-07 10:46 +0200
Re: LOOP dxf <dxforth@gmail.com> - 2025-06-29 13:04 +1000
Re: LOOP (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 16:04 +0000
DO..LOOP and stack shuffling (was: OOS approach revisited) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-06-28 17:46 +0000
Re: DO..LOOP and stack shuffling Hans Bezemer <the.beez.speaks@gmail.com> - 2025-07-01 13:53 +0200
Re: DO..LOOP and stack shuffling dxf <dxforth@gmail.com> - 2025-07-03 13:59 +1000
Re: DO..LOOP and stack shuffling anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-07-03 07:50 +0000
Re: OOS approach revisited Hans Bezemer <the.beez.speaks@gmail.com> - 2025-06-30 15:43 +0200
Re: OOS approach revisited dxf <dxforth@gmail.com> - 2025-06-27 13:39 +1000
csiph-web