(define (foo x) (cond ((null? x) 0) ((not (list? (car x))) (+ 1 (foo (cdr x)))) (else (+ (foo (car x)) (foo (cdr x))))))

Now for the second part, I'm supposed to modify the function to take a list and an atom as parameters, and return the total number of instances of that atom, also regardless of depth. Here's where I've run into trouble. What I have at the moment is:

(define (foo x y) (cond ((null? x) 0) ((not (list? (car x))) (( = (car x) y)(+ 1(foo ((cdr x) y))) ((eq? (car x) y)(+ 1 (foo ((cdr x) y)))))) (else ((+ foo ((car x) y))) (foo ((cdr x) y)))))

Perhaps it's my "newness" to functional programming, but I cannot find the problem. When I attempt to execute a trial run, with something like:

(foo '(1 2 3 2 1) 1)

I get this error message: "procedure application: expected procedure, given: (2 3 2 1); arguments were: 1" and it highlights the (( = (car x) y) line. But the error message confuses me further. It seems to me that that is what should happen, after the equivalence evaluation, it recursively passes the cdr and the atom. So.... what gives? If you find the time to look this over and give me a push in the right direction, I would greatly appreciate it. Thanks, Josh