Held Friday, February 16, 2001
Today we continue our exploration of recursion over lists through
experimentation and reflection.
- On the days when homeworks are due, I get a lot of email whose
title is simply "Homework" or "Homework 2" or whatever. I file
those away until I'm ready to grade. If you need help on a homework,
please title your message Help on Homework or
- Many of you clearly did not finish HW2 (or at least didn't get it
- You need to start earlier.
- You may have an extension until Monday.
- However, you do still have other work to do for the course.
- I'll do my best to get HW2 graded over the weekend. I again
plan to post my comments publically.
- You have two assignments for next Friday, a lab writeup and a homework.
- Some people were confused about the take home: I'm distributing it
- You may not have gotten this idea from the readings, but we define
more than procedures recursively: We also define some data
- Lists: A list is either
- the empty list (base case)
- the cons of a value and a list (recursive case)
- Natural numbers: A natural number is either
- the value 0 (base case)
- one plus a natural number
- Let's talk together about the problem of squaring all the values
in a list.
- My one-on-one discussions have suggested some ways
to look at the problem that may help others of you who
- Here's the problem: We need to square every element in a list
and create a new list of those squares.
- Remember that the basic point of recursion is to
- break up the problem into a small subproblem and a big subproblem
(but still smaller than the original problem),
- solve the small problem,
- assume you can solve the big subproblem
- Let's begin with the recursive case.
- Suppose you know how to create a list containing the square
of every element but the first.
- How can you use that result to create a list containing
the square of every element?
- Now let's consider the base case. For recursion over lists,
the empty list, the typical base case involves an empty
list or the singleton list.
- What is the result of squaring every value in the empty list?
- It may help to think about the kind of valur our procedure
is supposed to return (is it a number, a symbol, a string, a
list, or something else).
- Let's try to identify some patterns of recursion over lists.
- That is, the general structure of kinds of Scheme procedures
that work on lists.
- Here's one category of recursion that we did a few times:
apply some operation to every element of a list.
- How do we express the general form of that category?
- What other kinds of things do you do to lists?
- What is the general form for those things?
- What things are likely to be difficult or wrong in one of
your recursive procedures?
- I see many people having trouble with the base case. It
may help to think about what kind of thing the procedure
- I know that you sometimes write procedures that run forever
(I do, too; I wrote one yesterday). Make sure that when
you do the recursive call, you're using something closer
to the base case.
Friday, 12 January 2001
- Created generic outline format for class.
Friday, 16 February 2001