Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!think.com!mintaka!mit-eddie!uw-beaver!ubc-cs!alberta!ncc!idacom!rob From: rob@idacom.uucp (Rob Chapman) Newsgroups: comp.lang.forth Subject: Re: Use explicit arguments Message-ID: <1991Feb4.091009.11606@idacom.uucp> Date: 4 Feb 91 09:10:09 GMT References: <387@rc6.urc.tue.nl> Reply-To: rob@idacom.UUCP (Rob Chapman) Organization: IDACOM, a dvision of HP Lines: 38 In article <387@rc6.urc.tue.nl> wsbusup@eutws1.win.tue.nl (Jan Stout) writes: >True enough using DO/LOOP often involves some stackacrobatics to get the >right parameters, but then again DO/LOOP enables easier indexing >"in the loop" with I so will probably execute faster. >As an example: > >: TYPE SWAP OVER + > ?DO I C@ EMIT LOOP ; >instead of >: TYPE FOR C@+ EMIT NEXT ; >with : C@+ 1+ DUP 1- C@ ; This is fine for byte size cells but if you're incrementing through an array of CELL size cells, simply: : DOTS ( a \ n -- ) FOR @+ . NEXT DROP ; instead of any of: : DOTS ( a \ n -- ) 0 ?DO DUP @ . CELL + LOOP ; : DOTS ( a \ n -- ) 0 ?DO DUP I CELL * + @ . LOOP ; : DOTS ( a \ n -- ) CELL * OVER + SWAP ?DO I @ . CELL +LOOP ; I assume the stack diagram for @+ ( a -- a+ \ n ). These incrementing fetch words are some of the newer "ideas" injected into the Forth domain by Chuck. He's had a chance to see what Forth really looks like in hardware. These words usually translate to single assembler instruction, or very few. I consider these words and the FOR NEXT loop to be a better factoring of indexing and looping functionality. >Again I don't understand your enthousiasm for FOR/NEXT over DO/LOOP. There are two ways of judging a new idea: 1. Reject it and try and find ways to substantiate your rejection (you will always succeed). 2. Accept it and try it with a positive attitude. Rob