Paste: Translating Haskell to Factor

Author: Alan Mock
Mode: factor
Date: Wed, 25 Mar 2009 22:41:33
Plain Text |
primes = 2:filter isPrime [3,5..]
    where isPrime x =
    	all (\ y -> x `mod` y /= 0) $ takeWhile (\ p -> p*p <= x) primes 

DEFER: primes
:: is-prime ( n -- ? ) primes [ sq n <= ] lwhile [ n swap mod 0 = not ]
        lmap f [ and ] foldl ;
: primes ( -- list ) [ 2 ]  [ odds  [ is-prime ] lfilter  ]  lazy-cons ;

New Annotation

Summary:
Author:
Mode:
Body: