Closed StepfenShawn closed 1 year ago
(define (filter predicate sequence) (cond ((null? sequence) nil) ( (predicate (car sequence)) (cons (car sequence) (filter predicate (cdr sequence))) ) (else (filter predicate (cdr sequence))) ))
Then I run it:
> (filter odd? (list 1 2 3 4)) Exception: variable nil is not bound
But I change nil to '(), it's working correctly.
nil
'()
Scheme is not Common-Lisp. you can add this line of code before filter procedure:
filter
(define nil '())
Got it, thanks! @AiziChen
Then I run it:
But I change
nil
to'()
, it's working correctly.