CSC151 2010S, Class 26: Recursion with Helper Procedures Overview: * Notes on basic recursion. * Helper recursion: Computing intermediate results "as you go" * A term: Tail recursion. * Lab Admin: * I hate Tuesdays! (Too many students are missing today.) * Reading for Wednesday: Unit Testing. * Exam 2 distributed. * Due next Wednesday. * For this week, send me questions via email. * If you need in-person help, talk to Dr. Davis. * Are there any final questions on Assignment 6? * No CS Extras or CS Table this week. Exam 6 questions * Problem 1: Can we assume that the list of color names only include color names, and not things like "borgledyborgle"? Yes, assuming you document that requirement. * Problem 2: Can we have turtle-triangle? Yes. * Problem 3: Can we have some sample images? Eventually. Notes on Homework 6 * Your transformations of the Weinman image may be different. (Weinman wrote his in a different language; we're not sure why he got different results.) * For redder-greener-bluer, what do we do if two compnents are the same? * Whichever comes first * Return the original color * It's up to you Notes on Basic Recursion: Consider the filter-out-dark procedure: (define filter-out-dark (lambda (lst) (if (null? lst) null (if (rgb-dark? (car lst)) (filter-out-dark (cdr lst)) (cons (car lst) (filter-out-dark (cdr lost))))))) We may find it a bit easier to understand it in these terms (define filter-out-dark (lambda (lst) (if (null? lst) null (let ((filtered-rest (filter-out-dark (cdr lst)))) (if (rgb-dark? (car lst)) filtered-rest (cons (car lst) filtered-rest)))))) Today's reading: Yet another technique for recursion: We carry along an extra parameter in which we build the result as we go Questions! * None Lab! Reflection ; A better way to define difference (define difference (lambda (numbers) (if (null? numbers) 0 (- (car numbers) (sum (cdr numbers)))))) ; A better way to define sum-red (define sum-red (lambda (colors) (sum (map rgb-red colors)))) or, if your brain is wired right (define sum-red (o sum (l-s map rgb-red)))