# Class 17: Recursion with Lists (1)

Back to Recursion Lab. On to Recursion with Lists (2).

Held: Thursday, 25 September 2003

Summary: Today we continue our investigation of recursion over lists by conducting a number of experiments.

Related Pages:

Due

Assignments

Notes:

• Are there questions on Exam 1?

Overview:

## Patterns of Recursion

• I find it useful to think about the pattern one uses to design certain kinds of procedures.
• Here's the pattern of a typical recursive procedure:
```(define proc
(lambda (val)
(if (base-case-test)
(base-case val)
(combine (partof val)
(proc (simplify val))))))
```
• When the value you're working with is a list and your base case is the empty list, the form is somewhat simpler:
```(define proc
(lambda (lst)
(if (null? lst)
null-case
(combine (onestep (car lst))
(proc (cdr lst))))))
```
• When the value you're working with is a list and your base case is the singleton list, the form is similar.
```(define proc
(lambda (lst)
(if (null? (cdr lst))
singleton-case
(combine (onestep (car lst))
(proc (cdr lst))))))
```

## Closest to Zero

• Many of you seemed to have some problem with this exercise.
• Don't worry, every year people have some trouble with it. That's why I continue to assign it.
• One intent of the problem is to remind you not to try to do too many things at once.
• We'll look at some details in class.

## History

Thursday, 28 August 2003 [Samuel A. Rebelsky]

• Created automatically.

Back to Recursion Lab. On to Recursion with Lists (2).

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 9 13:59:40 2003.
The source to the document was last modified on Mon Sep 1 13:30:51 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Outlines/outline.17.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu