Sujet : DO..LOOP and stack shuffling (was: OOS approach revisited)
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forthDate : 28. Jun 2025, 18:46:49
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Jun28.194649@mips.complang.tuwien.ac.at>
References : 1 2 3 4
User-Agent : xrn 10.11
minforth@gmx.net (minforth) writes:
IIRC DO..LOOPs had been a hack for computers in the 60s.
A rather ugly hack, born out of necessity, slow and
often cumbersome to use.
Could you elaborate on "a hack for computers in the 60s"?
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. To gain these advantages, I
often prefer to massage the start and limit values more than
otherwise. E.g., to walk through a cell array in the forward
direction, I usually prefer
( x y addr u ) cells bounds ?do ( x1 y1 )
... i @ ...
1 cells +loop
rather than
( x y addr u ) 0 ?do ( x1 y1 addr )
... dup i th @ ...
loop
drop
because I then can access x1 and y1 in the loop without ADDR being in
the way.
- anton
-- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.htmlcomp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/EuroForth 2024 proceedings:
http://www.euroforth.org/ef24/papers/