Code: Select all

`;max is currently set at 50 in the REPL`

(define (sieve nums)

(if (pair? nums)

(let ((head (car nums)))

(if (< (* head head)

max)

(cons head

(sieve (filter (lambda (x)

(not (= 0 (modulo x head))))

(cdr nums))))

nums))

(define (filter pred xs)

(if (pair? xs)

(let ((head (car xs))

(tail (cdr xs))

(if (pred (head))

(cons (head)

(filter pred tail))

(filter pred tail))

'()))))

'()))

however, when I test it on a list of numbers, nothing seems to happen. At least "filter" seems to work correctly

Code: Select all

`> (+ 1 1)`

2

> (filter (lambda (x) (not (= 0 (modulo x 2)))) '(2 3 4 5 6 7 8 9))

(3 5 7 9)

> (sieve '(2 3 4 5 6 7 8 9))

>

any suggestions?

(also, general comments would be appreciated. I'm new to this language)