Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!cica!iuvax!purdue!bouma From: bouma@cs.purdue.EDU (William J. Bouma) Newsgroups: comp.lang.forth Subject: Re: New Directions: 'I' is broken in Forth Message-ID: <9379@medusa.cs.purdue.edu> Date: 24 Jan 90 18:12:05 GMT References: <9001241639.AA08039@jade.berkeley.edu> Organization: Department of Computer Science, Purdue University Lines: 43 > 0 FOR ." x" NEXT --> x > 1 FOR ." x" NEXT --> xx > 2 FOR ." x" NEXT --> xxx > >This is efficient to implement in hardware; for instance, it maps pretty >much directly onto the 680x0 DBRA instruction. ok, that is a good reason in some cases. But do loop can do the same stuff and do +loop is more general than this. Plus you have access to the counting index inside do loop. I can't understand how Chuck could argue to throw out do loop in favor of for next, (as you said in your previous post), since there doesn't seem to be that much difference. It doesn't seem very intuitive to have 0 FOR .. NEXT iterate one time. This is the same problem do loop has in always executing at least once. >> There is nothing wrong with the do-loop in forth other than the ugly >> way the index variable is handled. > >Some things wrong with the standard Forth DO .. LOOP: > > Can't EXIT from inside a DO ... LOOP > > Can't intermix use of the return stack and loop indices These are both side effects of the crummy way the index is handled. In my system these are not problems as my index doesn't sit on the return stack taking up space. > Termination conditions for +LOOP with positive and negative arguments > is not symmetrical. > > It always executes at least once. This is nearly always the wrong > thing. ?DO helps, but ?DO doesn't work well with negative arguments > to +LOOP These were just stupid design decisions. I agree the functionality of do loop should be changed, but that is no reason to trash the construct altogether. m n DO LOOP should count from n to m-1 and should not execute at all if m <= n. Likewise m n DO -1 +LOOP should count from n to m+1 ... -- Bill || ...!purdue!bouma