I am reading a programming languages book and it is asking me to to explain what the following Scheme function does (not sure, can someone help explain):
(define (x lis)
(cond ((null? lis) 0)
((not (list? (car lis)))
(cond
((eq? (car lis) #f) (x (cdr lis)))
(else (+ 1 (x (cdr lis))))))
(else (+ (x (car lis)) (x (cdr lis))))))
It counts the number of leaf nodes a nested list structure, ignoring
#f. It uses a recursive procedure:caris not a list:caris#f, we recurse on thecdrand return that.caras 1, and add that to the result of recursing on thecdr.carandcdr, and add them together.