CSC151, Class 21: Recursion Revisited Revisited Admin: * Ignore this line, it is a test * EC Talk, Monday, 4:15, Civil War Mourning, ARH 102 * EC Talk, Today, 4:30, Science 3821, DrFu * Other good things for you to do at 11 am * See Gene Gaub play piano * See David Harrison talk about International Studies Goals for Today: * Finish Tuesday's lab * Finish Monday's lab Things you should think about when writing recursive procedures * Think about the return value in the base case * In particular, make sure that it's the right type of thing * If you are writing: contains-a-color? * The base case should probably be #t or #f * If you are writing: (count-colors lst), that counts the number of colors in a list * The base case should probably be a number * For the empty list, that number should probably be 0 * If you are writing: (darkest-color lst), that finds the darkest color in a list of ONLY colors * Return a color (not a list, not a boolean, not a number, but a color)\ * When base case? When there's only one element in the list * What base case? That color * What precondition: The list must have colors (ooh, we can use contains-a-color?) * Sam's reference page is wrong, or so someone claims * cddr vs caddr * What should (cddr (list 1 2 3 4 5)) be? (3 4 5) * What should (cddr (list 1)) be? "There's only one thing, so ..." ERROR (or, "Success") * What should (cddr (list 1 2)) be? The empty list * Nope, it works JUST AS SAM CLAIMED! * But what the nice friendly successful students wanted was the third element of the list. * THe cddr is a list, not an elemnt * The car of the cddr is the third element of the lists: caddr