; takes an items and a list of symbols ; and checks for membership of item in lst (define (memq item lst) (cond ((null? lst) #f) ((eq? item (car lst)) lst) (else (memq item (cdr lst))))) ; counts the number of times symbol item ; occurs in top level of lst (define (item-count item lst) (define (item-count-iter sublist count) (let ((next-sublist (memq item sublist))) (if (not next-sublist) count (item-count-iter (cdr next-sublist) (+ count 1))))) (item-count-iter lst 0)) ; takes two expressions and is #t if they are the ; same symbols, or if they are lists with same elements ; and structure -- i.e., they look the same (define (my-equal? s1 s2) (cond ((symbol? s1) (eq? s1 s2)) ((symbol? s2) #f) ((and (null? s1) (null? s2)) #t) ((or (null? s1) (null? s2)) #f) (else (and (my-equal? (car s1) (car s2)) (my-equal? (cdr s1) (cdr s2))))))