(define (square x) (* x x)) ; sums the squares of all odd elements in a tree (define (sum-of-odd-squares tree) (cond ((null? tree) 0) ((not (pair? tree)) (if (odd? tree) (square tree) 0)) (else (+ (sum-of-odd-squares (car tree)) (sum-of-odd-squares (cdr tree)))))) ; returns a list containing those ; elements of lst that return non-#f for ; test (define (filter test lst) (cond ((null? lst) ()) ((test (car lst)) (cons (car lst) (filter test (cdr lst)))) (else (filter test (cdr lst))))) ; put together the elements of lst using ; binary-op (define (accumulate binary-op init-val lst) (if (null? lst) init-val (binary-op (car lst) (accumulate binary-op init-val (cdr lst))))) ; makes a list o[]ut of elements between ; lo and hi (define (enumerate-interval lo hi) (if (> lo hi) () (cons lo (enumerate-interval (+ lo 1) hi)))) ; enumerates the leaves of a tree (define (enumerate-tree tree) (cond ((null? tree) ()) ((not (pair? tree)) (list tree)) (else (append (enumerate-tree (car tree)) (enumerate-tree (cdr tree)))))) (define (sum-of-odd-squares tree) (accumulate + 0 (map square (filter odd? (enumerate-tree tree)))))