~jojo/Carth

c79cd28687482d6aa9df25fb5fd39c61a2c49ce5 — JoJo 1 year, 5 months ago 69e0965
Add example sieve.carth with the Sieve of Eratosthenes

Not the prettiest, but still a pretty good example of the power of
Carth. Runs for quite long -- 17359 iterations last I tried. That's
pretty good, considering the filters just keep piling on.
1 files changed, 13 insertions(+), 0 deletions(-)

A examples/sieve.carth
A examples/sieve.carth => examples/sieve.carth +13 -0
@@ 0,0 1,13 @@
(import std)

(define (main Unit)
  (let ((primes (sieve (range-from 2))))
    (for primes (<o display show-int))))

(define (sieve xs)
  (Iter (fun (_)
          (match (next! xs)
            (case (Pair x xs')
                  (Some (Pair x
                              (sieve (filter (<o not (flip divisible? x))
                                             xs')))))))))