home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,390 of 117,927   
   dxf to Hans Bezemer   
   Re: DO..LOOP and stack shuffling   
   03 Jul 25 13:59:16   
   
   From: dxforth@gmail.com   
      
   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.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca