[comp.lang.forth] FOR -I -R> NEXT

wsbusup@eutws1.win.tue.nl (Jan Stout) (02/19/91)

MB>> I tend to agree on the readability & don't consider Mitch's 0 ?DO a real
MB>> solution, letting the programmer type what he knows will be 'ignored' by
MB>> the compiler.(see below)
MB>
MB>Why is this optimization any different from any other optimization?
MB>
MB>If the compiler can generate better code by recognizing a special case,
MB>then why not let it do so?
MB>

If the FOR NEXT approach of using 1 parameter is more usefull,
I'd find it strange to recognize this fact by using 0 ?DO LOOP
to express that idea. 

MB>(There is one less-serious problem too: what is the name of the FOR .. NEXT
MB>loop index?).

The key issue, in my view, of the FOR NEXT approach is to keep the index
nameless, and in fact allow no reference to it at all.
This to prevent people to use to VERY implementation-dependant >R R@ R>.

By the way I is also inappropriate (see Robert Berkeys DO LOOP implementation).
In my opion ONE UPCOUNTING index is so scarcely used that using the
DO LOOP's I index is often inconvenient. (Of course the same applies to
the DOWNCOUNTING FOR NEXT index).

To keep the indexaddressing uniform I therefore propose to use
on (data:)stack indexes.

The more-serious problem U didn't mention is that of the FOR NEXT 'LEAVE',
for it's absense in a way caused ppl to code FOR WHILE NEXT 2R> >R DROP THEN
loops thereby making explicit use FOR NEXT implementation details.
LEAVE is supposed to factor out this details. BTW following your advise
on introducing old names, in my system PASS is used to skip the NEXT.
(I apoligize if this name or function already is in BASIS xx,
 but the last un-RTFed BASIS I received was #10 :)

Implementation note:
In my system ?FOR executes n times by branching directly to NEXT
  after saving the index.
NEXT checks for a <>0,
  if it's there it tries to remove it by decrementing
  and finally branching to the code after ?FOR.
  if it's not there then 0 is, so it's time to drop the index
  and continue with the code following.
PASS removes the <>0, inserts a 0 and branches to NEXT. 
  (Thus leaving the index removal to NEXT exclusively)
 
MB>Mitch Bradley, wmb@Eng.Sun.COM

Jan Stout, wsbusup@eutws1.win.tue.nl


PS I like the proposed OBSOLETE (EJ). 

dwp@willett.pgh.pa.us (Doug Philips) (02/21/91)

In article <437@rc6.urc.tue.nl>,
	wsbusup@eutws1.win.tue.nl (Jan Stout) writes:
> If the FOR NEXT approach of using 1 parameter is more usefull,
> I'd find it strange to recognize this fact by using 0 ?DO LOOP
> to express that idea. 

I agree.  DO  LOOP  and FOR  NEXT are not exactly isomorphic, but they
overlap by a lot.

> MB>(There is one less-serious problem too: what is the name of the FOR .. NEXT
> MB>loop index?).
> 
> The key issue, in my view, of the FOR NEXT approach is to keep the index
> nameless, and in fact allow no reference to it at all.
> This to prevent people to use to VERY implementation-dependant >R R@ R>.

I like this idea.  It has always bugged me that DO LOOP has muddied the
stacks so as to complicate early exit and access to the data stack.  
BLEAH.  My preferred idea (hare freakin' brained) is something more like:
	Count ' Word-To-Repeat DO-TIMES

I'm still up in the air about how and even if, Word-To-Repeat, can tell
DO-TIMES to stop early.  DO-TIMES should not pollute the data nor the
return stacks (I'm a little less adament about the return stack).

> PS I like the proposed OBSOLETE (EJ). 

Me too.

-Doug
---
Preferred:  dwp@willett.pgh.pa.us	Ok:  {pitt,sei,uunet}!willett!dwp