Path: utzoo!attcan!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Data Structures Message-ID: <1097.UUL1.3#5129@willett.UUCP> Date: 8 Jun 90 04:08:30 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 52 Date: 06-06-90 (10:48) Number: 3324 (Echo) To: ALL Refer#: NONE From: CHARLIE HITSELBERGER Read: (N/A) Subj: PRIME NUMBERS Status: PUBLIC MESSAGE I was just sort of messing around the other day, trying to write a primes generator in Forth83. Here's what I came up with: 2VARIABLE NUMER 3. NUMER 2! VARIABLE DENOM : PRIMES ( -- ) CR BEGIN 3 DENOM ! FALSE BEGIN DROP NUMER 2@ DENOM @ UM/MOD DROP DUP IF DENOM @ DUP M* NUMER 2@ D> 2 DENOM +! ELSE TRUE THEN UNTIL IF NUMER 2@ 20 D.R THEN NUMER 2@ 2 M+ NUMER 2! ?TERMINAL UNTIL ; here's the BASIC equivalent: 10 N=3 20 D=3 30 IF N/D>INT(N/D) THEN 50 40 N=N+2:GOTO 20 50 IF D*D