Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: ANS TC Magnet for LOOPS, EXIT, Term. Message-ID: <2126.UUL1.3#5129@willett.pgh.pa.us> Date: 17 Dec 90 00:23:37 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 52 Category 10, Topic 16 Message 94 Sat Dec 15, 1990 F.SERGEANT [Frank] at 11:08 CST Yesterday I sent in the following proposal. If I have made any errors in the facts or history of FOR NEXT please let me know: ================================================================= ANSI X3J14 FORTH TECHNICAL PROPOSAL ----------------------------------- TITLE: FOR ... NEXT Should Execute the Body Count Not Count+1 Times PROPOSAL: If FOR ... NEXT and its index or count are mentioned in the Standard, make the loop body execute u times rather than u+1 times. For example: : TEST1 ( u -) FOR ." A" NEXT ; 0 TEST1 should print nothing at all 3 TEST1 should print AAA : TEST2 ( u -) FOR I . NEXT ; 0 TEST2 should print nothing at all 3 TEST2 should print 2 1 0 DISCUSSION: As short-hand for the sake of discussion, the version I'm proposing will be called "superior" and the u+1 version will be called "inferior." The (short and thin) tradition of having the body of a FOR NEXT loop execute u+1 times for a non-zero count and execute one time for a zero count stems strictly from hardware efficiency considerations on the NOVIX and originated with cmFORTH for the NOVIX. From there it was carried over to the RTX. Rob Chapman in his botFORTH (on RTX & 68000 machines) and I in my Pygmy Forth (on 80x86 MS-DOS machines) have already converted to the superior FOR NEXT. Our experience with this is favorable. I understand from Rob that he discussed this possible change with Charles Moore at the 1990 FORML and that CM had no objection to the superior version. When the body always executes at least once and executes u+1 times, programs very often must use an awkward work-around to test for the zero count in order to bypass the loop. The following phrase is common, and wasteful, and ugly: ?DUP IF 1- FOR ... NEXT THEN with the new version the above phrase would be FOR ... NEXT Clearly superior! In cases, where you want the body to execute u+1 times, that is easily achieved with the superior version by saying 1+ FOR ... NEXT The "tradition" of the inferior version is far too short to justify embedding it into the Standard. In those special cases where a little extra performance can be wrung out of a Forth "engine" by using the inferior version, vendors are still free to define it, but with a different name. DATE: 14 December 1990. SUBMITTED BY: Frank Sergeant 809 W. San Antonio St. San Marcos, Texas 78666 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp