Reputation: 406
I get this TypeError below that when I run the following code. I think it's because I'm trying to test for an empty list using "null?". Why is that causing an error?
TypeError: Cannot read property 'apply' of undefined [NumberLister, NumberLister, NumberLister, NumberLister, NumberLister, car]
(define NumberLister(lambda(numberList)
(if(null? numberList)
(= (+ 1 1) 2)
)
(display (car numberList))
(display "\n")
(NumberLister (cdr numberList))
)
)
(NumberLister '(1 3 5 6))
Upvotes: 0
Views: 138
Reputation: 236004
Normally you can't put more than one expression in the consequent or alternative part of an if
expression, if needed group the expressions in a begin
form. Also, what's the use of (= (+ 1 1) 2)
? just return #t
, like this:
(define NumberLister
(lambda (numberList)
(if (null? numberList)
#t
(begin
(display (car numberList))
(display "\n")
(NumberLister (cdr numberList))))))
Upvotes: 4