Reputation: 21
;Question 3
(defun listcheck(lst)
(cond
((not (null lst))
(cond
((eq (car lst) 'a) (+ (listcheck (cdr lst)) 1))
( T (listcheck (cdr lst)))
)
)
)
0
)
this function prints out 0 at all times not sure where im going wrong any input would help
Upvotes: 0
Views: 50
Reputation: 780798
It's printing 0
because the function ends with 0
, outside the cond
. So it returns this in all cases, not just the base of the recursion. That should only be returned when lst
is null.
(defun listcheck(lst)
(cond ((null lst) 0)
((eq (car lst) 'a) (+ (listcheck (cdr lst)) 1))
(T (listcheck (cdr lst)))))
Upvotes: 2