Announcement

Collapse
No announcement yet.

Been playing with gforth

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Been playing with gforth

    Back in the very early 1980s I used AceForth on a Tandy Xenix to write an autoparts hardware application for a client.

    A couple weeks ago I installed gforth and began playing with it. I wrote a program that computes the number of primes from 0 to some given number.
    In a Konsole running gforth I computed all the primes between 0 and 10,000,000. It took 23 seconds.
    Code:
    : PRIMES ( n - )
      2 SWAP 2 . 3 . 5
      DO DUP DUP * i < 
         IF 1+ 
         THEN 
         1 OVER 1+ 3
         DO     J I MOD 0=
                IF 1- LEAVE 
                THEN 
                2 
         +LOOP
         IF I . 
         THEN 
         2 
      +LOOP
      DROP ;
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.
Working...
X