; create an array for the sieve (setf candidates (make-array '(1000))) ; Set all array elements to true. Indices represent the integers (dotimes (i 999) (setf (aref candidates i) t) ) ; zero and one are not prime, turn them off (setf (aref candidates 0) nil) (setf (aref candidates 1) nil) ; 500 is good enough, 2*501 is > 1000 (dotimes (i 500) ; Find first ON element -- must be prime (when (aref candidates i) ; Turn off all multiples of p, starting with 2*p (dotimes (j (/ 1000 i)) (when (<(* i (+ j 2)) 1000) (setf (aref candidates (* i (+ j 2))) nil) ) ) ) ) ; print all primes (dotimes (i 999) (when (aref candidates i) (format t "~S is prime~%" i) ) )