CSC151 2007S, Class 18: Recursion Basics Admin: * Exam 1 is due today (or Monday, if you need the extra time) We'll go over the exam next Thursday. * Assignment 8 is now available (and due Tuesday). * There is a reading for Monday. It's about a different kind of recursion, tail recursion. * Extra Credit for going to the Science Poster Session on Saturday Look for Amanda M's poster (Cortisol), Emily's poster (Why the GIMP Crashes and its all her fault), ... or the Social Studies Poster Session, Becky's poster (Politics of Mourning) * EC Family and Friends Fine Arts Percussion Band Saturday at 3:00 in front of Bucksbaum * EC G-Tones, Vox, Con-Brio Sunday at 2 p.m. in JRC 101 Overview: * The idea of recursion. * A sample recursive procedure: sum. * Another example: Filtering. * Lab /Today: Recursion/ * Recursion: A technique for doing repetition Alternate to: Type it a lot of times Nest it a lot of times (rgb.greyer (rgb.greyer (rgb.greyer rgb.grey))) = The sky color at UofC, almost every day A few basic mechanisms for repetition: image.map, image.map!, region.compute-pixels!, map, foreach! * Recursion is the most general * Works with any kind of data * Produces any kind of result * We will start by recursing over lists * Key ideas * Procedures can call themselves ; Problem: Given a list of integers, compute their sum Strategy/Terminology: * First, find a simple enough case that you can solve: "The Base Case" * The empty list * Next, figure out how you can simplify non-simple cases * (cdr nums) * Call the same procedure on the simplified case: The recursive step (sum (cdr nums)) * Use that result to compute our final result Another example: Filtering * Given a list of integers, get rid of the even ones (define filter-out-evens (lambda (lst) (if (null? lst) null (if (even? (car lst)) (filter-out-evens (cdr lst)) (cons (car lst) (filter-out-evens (cdr lst)))))))$a Gloucester Marina = Glahstah Mariner /Reflection/ * Should I continue to assign partners? * What failed to make sense?