cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.95k stars 982 forks source link

Can not support "nil" #679

Closed StepfenShawn closed 1 year ago

StepfenShawn commented 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.

AiziChen commented 1 year ago

Scheme is not Common-Lisp. you can add this line of code before filter procedure:

(define nil '())
StepfenShawn commented 1 year ago

Got it, thanks! @AiziChen