Question: Consider the following Scheme function foo: (define (foo x) (cond ((null? x) 0) ((not (list? (car x))) (+ 1 (foo (cdr x)))) ((eq? x ())
Consider the following Scheme function foo:
(define (foo x) (cond
((null? x) 0) ((not (list? (car x)))
(+ 1 (foo (cdr x)))) ((eq? x ()) (foo (car x))) ((eq? x (x)) (foo x)) (#t (+ (foo (car x)) (foo (cdr x))))))
(a) Explain what the function computes and how. Dont just restate the function definition in English explain the algorithm. Hint: not all the code in this function does something useful.
(b) Show the result of executing the expression
(foo (((a b (c d)) (((d e)) f) g)))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
