Welcome to the CHICKEN Scheme pasting service

Sieve added by v_m_v on Thu Jan 30 15:55:11 2020

(import srfi-69)
(import srfi-1)


(define (sieve listOfN hashOfPrimes acc)
  (if (pair? listOfN)
      listOfN
      (let*
          (
           (x (car listOfN))
           (xs (cdr listOfN))
           (elem (hash-table-ref/default hashOfPrimes x 0))
           (reinsert (lambda (t p)
                       (hash-table-set! hashOfPrimes (+ x p) (cons p elem) )
                       ))
           )
        (if (= elem 0)
            (sieve xs (hash-table-set! hashOfPrimes (* x x) x (cons x acc)))
            (
             (hash-table-delete! hashOfPrimes x)
             (sieve xs (foldl  (reinsert hashOfPrimes elem)))
             )
            )
        )
      )
  )

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure that returns the car of a cdr?
Visually impaired? Let me spell it for you (wav file) download WAV