[comp.lang.forth] ANS TC Magnet for LOOPS, EXIT, Term.

ForthNet@willett.UUCP (ForthNet articles from GEnie) (02/28/90)

 Date: 02-26-90 (10:45)              Number: 2970 (Echo)
   To: IAN GREEN                     Refer#: 2961
 From: PETE KOZIAR                     Read: NO
 Subj: NESTED FOR LOOPS              Status: PUBLIC MESSAGE

 Well, the first possible problem is that the usual FORTH world uses 
 DO...LOOP instead of FOR...NEXT.  I haven't used the RTX processors, 
 but, on thier predecessors, the Novix chips, you needed to use -I 
 instead of I inside a FOR...NEXT loop. 

 As far as nested loops, here's an example for you to try: 

 : Goo 
    4 0 Do 
      5 0 Do 
        I . Space J . CR 
      Loop 
    Loop 
 ; 

 This should print out: 
 0 0 
 1 0 
 2 0 
 3 0 
 4 0 
 0 1 
 . 
 . 
 . 
 This is because I refers to the loop index of the current loop, and J 
 refers to the index of the next loop out.  Some FORTHs even have a K 
 for the nextmost outer loop; I have never seen an L. 

 Hope this helps! 
 ---
  * Via Qwikmail 2.01  The Baltimore Sun 
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (02/28/90)

 Date: 02-26-90 (08:19)              Number: 2974 (Echo)
   To: STEVE PALINCSAR               Refer#: 2965
 From: IAN GREEN                       Read: NO
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

    The reason for using FOR-NEXT is that I saw a comment comparing FOR 
 vs. DO in the RTX2001 data sheet. It said FOR runs several times faster 
 so I assumed that this was a standard word in Forth.

 >Ian, you're probably looking for something like this:
 >: LOOP_DEMONSTRATION  ( n2 n1 -- )
 >\ That is, both the inner and outer loop limits are on the stack
 >\ before this word executes.  You could put them there by fetching
 >\ from a couple of variables, or whatever other means you like.
 >   1 DO        ( Takes n1 from param stack, puts in on Rstack )
 >      1 DO     ( Takes n2 from param stack, puts it on Rstack )
           <SOMETHING>  ( whatever you want to execute )
 >      LOOP
 >   LOOP  ;
 >
    In the help conference I saw a note that described a different 
 syntax. It used the FOR-NEXT syntax and demonstrated the control 
 variable (I need to be able to use the control variable inside the loop)
 and it like your code used a 1. My question, what does the 1 do?

 The code was something like

 : FORSAMPLE 1 M FOR wordsequence NEXT ;

 Eventually I will get this together. Thanks

 Ian Green

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (02/28/90)

 Date: 02-26-90 (11:01)              Number: 2975 (Echo)
   To: STEVE PALINCSAR               Refer#: 2965
 From: MICHAEL HOBSON                  Read: NO
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

 Steve, have you forgotten that cmForth has a real FOR/NEXT construct?  
 He is programming for an RTX2001A Kit that has cmForth or the nearest 
 Harris equivalent on it.
 "The Elf" [^]-[^]
            \---/

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/01/90)

 Date: 02-27-90 (10:12)              Number: 2977 (Echo)
   To: IAN GREEN                     Refer#: 2974
 From: STEVE PALINCSAR                 Read: NO
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

 FOR - NEXT is a new syntax that Chuck Moore introduced within the past 
 couple of years.  DO LOOP is the standard forth loop syntax.  I believe 
 the forths for the RTX are related to the forth Chuck wrote for the 
 Novix forth chip (in fact, the RTX chip itself is a descendent of the 
 Novix chip that Chuck designed) -- may even be the same CMFORTH, for all
 I know.  And as we all know, the only "standards" Chuck Moore seems to 
 care about are his current standards of the hour.  Maybe an hour from 
 now, he'll have changed his mind, or created something new.
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/01/90)

 Date: 02-27-90 (10:15)              Number: 2978 (Echo)
   To: MICHAEL HOBSON                Refer#: 2975
 From: STEVE PALINCSAR                 Read: 02-27-90 (12:38)
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

 Yes, as a matter of fact, I did fail to notice any mention of the RTX 
 and cmForth in the discussion.  I do know that cmForth has a for/next, 
 but don't know how it works.  I did assume that Ian had gotten for/next 
 because it's a more common usage in other languages.  Anyway, no great 
 harm done, since after all do loop is in fact standard forth, and the 
 whole issue of loop limits on the stack instead of variables is crucial 
 to understanding what's going on in forth, right?  But thanks for 
 pointing out this crucial misunderstanding.
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/01/90)

 Date: 02-27-90 (10:20)              Number: 2980 (Echo)
   To: PETE KOZIAR                   Refer#: 2970
 From: IAN GREEN                       Read: NO
 Subj: NESTED FOR LOOPS              Status: PUBLIC MESSAGE

    Thanks, I am fiddling with Forth-83 as this is what I have for my PC 
 and trying to make the code compatible with the RTX's flavor of Forth 
 which is supposed to also be F-83 based.

 Ian Green

 NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886   
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

mef@aplcen.apl.jhu.edu (Marty Fraeman) (03/01/90)

In article <578.UUL1.3#5129@willett.UUCP> ForthNet@willett.UUCP (ForthNet articles from GEnie) writes:
>
> Date: 02-26-90 (08:19)              Number: 2974 (Echo)
>   To: STEVE PALINCSAR               Refer#: 2965
> From: IAN GREEN                       Read: NO
> Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE
>
>    The reason for using FOR-NEXT is that I saw a comment comparing FOR 
> vs. DO in the RTX2001 data sheet. It said FOR runs several times faster 
> so I assumed that this was a standard word in Forth.
>
Nope.  My impression is that the designers of the original Novix chip
had a cute way of doing the FOR-NEXT loop with only a minimal amount of
hardware.  Rather than make the hardware more complicated (amazingly,
the whole thing fit into a 4K gate array) they just invented a new loop
construct.  After all we are talking about Forth. -)  

While we were designing the Hopkins 32 bit Forth engine that later
became the SC32, we also struggled with this issue.  We finally came up
with a way to implement Forth 83 style do-loops in 2 cycles.  I believe
the Novix (and hence the Harris RTX 2000) design can do the FOR-NEXT
loop in just a single cycle.  However in all but the most trivial loops
this small difference is neglible.  

	Marty Fraeman

	mef@aplcen.apl.jhu.edu
	301-953-5000, x8360

	Room 13-s587
	Johns Hopkins University/Applied Physics Laboratory
	Johns Hopkins Road
	Laurel, Md. 20723

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/02/90)

 Date: 03-01-90 (06:32)              Number: 2986 (Echo)
   To: IAN GREEN                     Refer#: 2985
 From: STEVE PALINCSAR                 Read: NO
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

 Oh, certainly you'll be able to understand it.  Given one or two basic 
 concepts _that really are considerably different from most other 
 languages_ forth's pretty easy to figure out.  Incidentally, I got 
 bollixed up with line noise in trying to reply to a msg of yours in 
 anotheer conference, where you asked about the syntax of

    VARIABLE IFORGOTWHATYOUCALLEDIT  ;

 You don't need that trailing semicolon-- at least not with any "regular"
 forth.  Semicolon's a forth word, used to end colon definitions.
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/02/90)

 Date: 02-28-90 (22:52)              Number: 2987
   To: STEVE PALINCSAR               Refer#: 2977
 From: RAY DUNCAN                      Read: NO
 Subj: DO LOOPS IN FORTH             Status: PUBLIC MESSAGE

 The elements of the FOR...NEXT control structure are implemented in the
 Novix/RTX hardware.  When you code a DO...LOOP it has to be reduced to
 FOR...NEXT primitives for efficient execution, or DO...LOOP can be
 implemented in other, slower ways.

 NET/Mail : LMI Forth Board, Los Angeles, CA (213) 306-3530             
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (03/14/90)

 Date: 03-12-90 (23:13)              Number: 3022 (Echo)
   To: ALL                           Refer#: NONE
 From: BOB LEE                         Read: (N/A)
 Subj: FOR ... NEXT                  Status: PUBLIC MESSAGE

 Do I and J work in FOR NEXT constucts like they do in DO LOOPs? If so,
 then what is the meaning of I' (always zero?).

 NET/Mail : RCFB Golden, CO (303) 278-0364 VESTA & Denver FIG for Forth!
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'

ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/16/90)

Category 10,  Topic 16
Message 92        Sun Jul 15, 1990
R.BERKEY [Robert]            at 04:37 PDT
 
 
 From BAR0712.90:

[This was "formatted" to a degree unreadable.  I unformatted it.  -dwp]

<[Robert] R.BERKEY> I just noticed that FOR NEXT has "sys" on the stack.
<[Hail, Denver] JAX> "buf of courz, m'sieu"
<[Robert] R.BERKEY> That allows implementations some more options there, while
<[Robert] R.BERKEY> disallowing branches out of FOR NEXT loops.
<[Robert] R.BERKEY> DO LOOP is  "dest" so that means that there is only one item
<[Hail, Denver] JAX> Well, that's a poor description of DO ... LOOP then.
<[Robert] R.BERKEY> on the stack.
<[Hail, Denver] JAX> There oughta be   SYS   there.
<[Robert] R.BERKEY> Which means that DO LOOP security must go elsewhere.
<[Hail, Denver] JAX> I'll try to remember to mention that at Vancouver.
<[Robert] R.BERKEY> But if you make DO "sys" then you can't program
<[Robert] R.BERKEY> DO   WHILE   LOOP   ELSE  THEN   ( add an UNLOOP somewhere )
<[Hail, Denver] JAX> the 11th commandment: ( after "thou shalt not pick ...) :
<[Hail, Denver] JAX> THOU SHALT NOT UNLOOP!
<[Hail, Denver] JAX>  :-)
<[Robert] R.BERKEY> Huh?  What wrong with UNLOOP ?


Jan Stout writes, 900321:

  > 5. ?DO
    ...
    (Why not let the orig dest duo be sys anyway?)


About having "sys" in the definition, I tried to write up a proposal involving
such.  Here's the problem.  A point of ( -- orig dest ) is that it allows a
control structure to handle special processing in the case of zero iterations
of the loop.

   ?DO   ( orig0 dest0 )
      ...
   LOOP  ( orig0 )
      ...                       \ normal loop termination
   ELSE   ( orig1 )
      ...                       \ zero iterations
   THEN

But another point of the spec is that it allows a control structure to access
special processing in the case of early loop termination.  And both
simultaneously are of interest:

    ?DO   ( orig0 dest0 )
       ...
       WHILE   ( orig0 orig1 dest0 )
          ...
    LOOP    ( orig0 orig1 )
          ...                   \ normal loop termination
       ELSE   ( orig0 orig2 )
          ... UNLOOP            \ early loop termination
       THEN   ( orig0 )
       ...
    ELSE   ( orig3 )
       ...                   \ zero iterations termination
    THEN

Since the "sys" is for resolution by the loop, the logical order for ?DO is:
   ( orig0 sys0 dest0 )

This couples sys0 and dest0.  But since WHILE swaps the top of the control
flow stack, ( orig0 sys0 orig1 dest0 ), there's then no way for LOOP to find
the "sys".

Thereby, any extra values left by ?DO must be paralleled by any "dest" word,
such as BEGIN , so that WHILE will know how to do the swap.  It may not be
ideal, but the compiling part of  ?DO can have it's own stack, or use the
return stack, or all of the other control structures can be modified such that
dest  and  orig  always use the same number of stack elements.


Now, as to why BASIS gives   FOR NEXT   "sys" rather than control-flow stack
indications, I don't know.

-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (09/03/90)

Category 10,  Topic 16
Message 93        Fri Aug 31, 1990
D.RUFFER [Dennis]            at 13:33 EDT
 
From Elizabeth Rather, Chair, ANS X3J14 Technical Committee:

This is addressed to those who have been commenting extensively on our work on
UseNet and related boards.

3. Vectored execution:  ' and ['] provide execution tokens, and EXECUTE
executes them.  In between you can ! or , them into data structures as you
wish, and @ them when you need them.  An execution token is a cell wide, so
you can use CELLS or CELL+ to index through an array of tokens if you wish, to
get the effect of a "computed GOTO".  We have considered two other words,
PERFORM (equivalent to @ EXECUTE) and @EXECUTE (equivalent to @ ?DUP IF
EXECUTE THEN), both of which are in widespread practice, and as of B13 regard
either as too trivial an implementation to require.  Again, we consider it our
obligation to standardize capabilities (which @ EXECUTE is), and leave
optimizations to implementors.
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (12/17/90)

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

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (02/11/91)

Category 10,  Topic 16
Message 100       Sun Feb 10, 1991
F.SERGEANT [Frank]           at 15:16 CST
 
 To Jan Stout
 JS>So I think you unwillingly (?) created another FOR NEXTer.
 What a pleasure to hear that!  In return I'll ease off of my position  about
the decimal point indicating double precision.  (I may not change  my own
Forth in the immediate future, but at least I see what you mean  a little
better.)
 JS> : THRU ( 1st last)
 JS>   1+ OVER -
 JS>   FOR  DUP PUSH  LOAD  POP 1+  ?SCROLL  NEXT  DROP ;
  Thank you very much for the above.  How stupid of me not to have seen  it. 
At least learning and thinking are benefits from  arguments/discussions about
what should be in a Forth standard!
  (To anyone listening who doesn't follow all of the above, THRU in  cmFORTH
kept the index on the stack, and thus could not be used to load  a range of
screens that passed data on the stack across screen  boundaries.  I "solved"
it in Pygmy with a sledge hammer and wished for  an upcounting FOR NEXT index
to make it prettier.  Jan has showed me  how I should have done it.  By the
way the ?SCROLL is only used in the  debugging THRU (it allows a keypress to
temporarily halt the display).  It is omitted from the regular THRU.)
  And, furthermore, I am amazed and delighted that we are able to  converse
across such a distance: from central Texas to the Netherlands!   I understand
the Netherlands has a long history of free thinking and  tolerance of ideas.
  -- Frank
-----
This message came from GEnie via willett.  You cannot Reply to the author
using email.  Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, whatever).
Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (02/18/91)

Category 10,  Topic 16
Message 103       Fri Feb 15, 1991
F.SERGEANT [Frank]           at 23:38 CST
 
 > I find it amusing that Chuck introduced a bug in cmForth because of
 > his zeal for eliminating DO .. LOOP
 .
 There was no need in cmFORTH to compile colon or CODE definitions  across
screen boundaries, thus its THRU worked just fine. And, as Jan  Stout pointed
out, it is easily modified to allow compiling colon or  CODE words across
screen boundaries, if one's factoring is so poor (as  mine is on occasion)
that he needs that facility.
 .
 -- Frank
-----
This message came from GEnie via willett.  You cannot Reply to the author
using email.  Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, whatever).
Report problems to: dwp@willett.pgh.pa.us or uunet!willett!dwp

ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (04/11/91)

Category 10,  Topic 16
Message 34        Wed Apr 10, 1991
ELLIOTT.C                    at 13:17 EDT

[ If anyone would like a copy of one/more/all of these files, please
  drop me a note at one of the addresses at the end of this message.
  All binary files are UUencoded.  Files are then split (if necessary)
  into mailer-acceptable sized pieces and then mailed to you.
  In order for me to answer your request, you must:
      Include the line containing the file name. (so I know what you want.)
      Include your email address in the _body_ of the message.  You _must_
	  include an address *relative to* the InterNet or well known
	  UseNet site.
  -dwp]

 
Messages to Aug. '89 have been uploaded to library 10 as LOOP789.ARC
-----
This message came from GEnie via willett.  You *cannot* reply to the author
using e-mail.  Please post a follow-up article, or use any instructions
the author may have included (USMail addresses, telephone #, etc.).
Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp