CSC151.01 2006S, Class 28: Deep Recursion Admin: * Wednesday EC: * Transgendered UU Minister at 4:15 * Thursday EC: * Convo: Molly's friend (Interpretation of Race in American Museums) [may be cancelled - NOOOOOOO] * 4:15: "Women in Computer Science at Grinnell" * Are there questions on the project report? * One report per group. * Reading for Friday: Vectors Overview: * Lists, revisited. * Trees, introduced. * Deep recursion, considered. * Lab. /What is a list?/ * Lists are defined recursively. * Recursive definitions have * A base case: null * A recursive case: * A good, but incorrect, guess: pair of lists null, (cons null null), (cons null (cons null null)) * Another good, but insufficient, guess: A pair (cons 'a 'b) * A good, but non-recursive defintion: A sequence of pairs ending with null. * A pair in which the first element is /anything you want/ and the second is a list. /Observation: Process vs. Data/ * We typically use recursion for /process/ (how we do something) * Here, we use recrusion to describe /structure/ (how something is organized) * The natural numbers are either base case: 0 recursive case: the successor of a natural number (you get a successor by adding 1) * Note: Our recursive processes reflect these recursive structures /New Recursive Structure: The Tree/ * A tree is either base case: any non-pair value recursive case: a pair whose car is a tree and whose cdr is a tree * To recurse over trees, we must acknowledge their doubly-recursive nature (define recursive-proc (lambda (tree) (if (pair? tree) (COMBINE (recursive-proc (car tree)) (recursive-proc (cdr tree))) (BASE-CASE tree)))) * Two related issues: * Helpers with so-far less likely to be helpful * Husk and kernel still useful for checking preconditions /LAB!/ Some number trees 5 * * * / \ / \ / \ 5 7 * 3 3 * / \ / \ 1 8 6 12 That is 5 (cons 5 7) (cons (cons 1 8) 3) (cons 3 (cons 6 12)) Some non-number trees null * * * / \ / \ / \ "soren" 7 * 3 3 * / \ / \ "is" 8 6 'doomed That is null (cons "soren" 7) (cons (cons "is" 8) 3) (cons 3 (cons 6 'doomed))