# Class 07: Numeric Recursion

Back to Recursion with Lists. On to Local Bindings.

Held: Friday, 30 January 2004

Summary: Today we consider recursion over a different domain, that of the natural numbers.

Related Pages:

Assignments:

Notes:

• Are there questions on homework 2?
• Thoughts on Convo?
• About mental health and therapy.

Overview:

• Introduction to numeric recursion.
• Lab.

## Recursion with Numbers

• While most of the recursion we've been doing has used lists as the structure to recurse over, you can recurse with many different kinds of values.
• It is fairly common to recurse using numbers.
• The natural base cases for integers are when the parameter reaches 0 or 1.
• There are, of course, other alternatives
• The natural parameter for recursive procedure calls typically involves subtracting 1 from the argument.
• There are, of course, other alternatives, such as dividing by two.
• Since I like patterns, here's a sample pattern:
```(define RECURSIVE-PROCEDURE
(lambda (num)
(if (zero? num)
BASE-CASE
(COMBINE num (RECURSIVE-PROCEDURE num)))))
```

## Lab

• Do the lab.
• Since it's comparatively short, we should have a few minutes to reflect at the end.

## History

Back to Recursion with Lists. On to Local Bindings.

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 Fri May 7 09:43:06 2004.
The source to the document was last modified on Tue Jan 13 10:26:10 2004.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Outlines/outline.07.html`.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu