CSC151 2007S, Class 43: Deep Recursion, Revisited Admin: * Are there questions about Assignment 15? Biologists and Biological Chemists everywhere say "It's fun and it's extra credit, give it a try." * Are there questions about The Project? * Perhaps not so suprisingly, there are no Thursday extras this week. * Reading for tomorrow: Association Lists. * Reading for Monday: Higher-Order Procedures. Overview: * Lists, revisited. * Trees, introduced. * Deep recursion, considered. Review of Friday: * Talked about Pears (or maybe pairs) * Pairs are used to make lists BAD CODE FOR FIND A COLOR IN A TREE (define ctree.contains? (lambda (ctree color) ; Is the car of the first node color? (cond ; If the ctree is itself a color and equals ; the color, return true ((and (rgb? ctree) (equal? ctree color)) #t) ((and (not (pair? ctree)) (not (equal? ctree color))) #f) ((equal? (car ctree) color) #t) ((pair? (car ctree)) (ctree.contains? (car ctree) color)) (else (ctree.contains? (cdr ctree) color))))) a ;;; Purpose: ;;; Determine if ctree contains color. (define ctree.contains? (lambda (ctree color) (if (not (pair? ctree)) (equal? ctree color) (or (ctree.contains? (car ctree) color) (ctree.contains? (cdr ctree) color))))) ; Simplest trees: One color (define ctree1 color.red) ; Two element tree (define ctree2 (cons color.blue color.black)) ; Three element tree (define ctree3 (cons color.grey (cons color.black color.white))) ; Four element tree (define ctree4 (cons (cons color.cyan color.semi-sweet-chocolate) (cons color.midnight-blue color.dark-brown)))