; sieve calls sift, which recursively performs a sieve (defun sieve2 (n) (filternils (sift 2 (ceiling (sqrt n)) (nlist 2 n))) ) ; (sift a b nums) remove all the multiples of numbers from a to b, from nums ; (ie. replaces members of nums with nil) (defun sift (cnt end nums) (cond ((> cnt end) nums) (t (cons (car nums) (sift (1+ cnt) end (sift_thru 1 cnt (cdr nums))) ) ) ) ) ; (siftthru a b nums) strikes off every bth entry in nums (replace with nil) ; a counts from 1 thru the end of the list (defun sift_thru (i n nums) (cond ((null nums) nil) ((zerop (mod i n)) (cons nil (sift_thru (1+ i) n (cdr nums)))) (t (cons (car nums) (sift_thru (1+ i) n (cdr nums)))) ) ) ; (nlist a b) recursively creates a list of integers from a to b (defun nlist (a b) (cond ((>= a b) (list b)) (t (cons a (nlist (1+ a) b) ) ) ) ) ; (filternils m) recursively removes all nil's from list m (defun filternils (l) (cond ((null l) nil) ((null (car l)) (filternils (cdr l))) (t (cons (car l) (filternils (cdr l)))) ) )