home .. forth .. colorforth mail list archive ..

[colorforth] Sieve


Hello.

You can learn a lot by looking at other Forths, especially when they have
source code.

------------------

\ btd changed sive to work the same way as the "C" benchmark and forth 
\ benchmarks  listed in Byte. They print diferently.

\ mdh 2/12/87 names changed to prevent redefinition of BENCH.

( SIEVE )

DECIMAL 8190 CONSTANT TSIZE

VARIABLE FLAGS TSIZE ALLOT

: <SIEVE>  ( --- #primes )  FLAGS TSIZE 1 FILL
 0  TSIZE 0
 DO   ( n )  I FLAGS + C@
      IF    I  DUP +  3 +   DUP I +  (  I2*+3 I3*+3 )
           BEGIN  DUP TSIZE <  ( same flag )
           WHILE  0 OVER FLAGS + C! (  i' i'' )   OVER +
           REPEAT 2DROP  1+
      THEN
 LOOP       ;

: SIEVE  ." 10 iterations " CR  0   10 0 
  DO     <SIEVE> swap drop 
  LOOP   . ." primes " CR ;

----------------------------------

Regards...Martin
------------------------

To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site   -   http://www.colorforth.com
Wiki page http://kristopherjohnson.net/wiki/ColorForth
ColorForth index http://www.users.qwest.net/~loveall/c4index.htm