Fundamentals of Computer Science I (CS151.01 2006F)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
Back to Recursion. On to Recursion with Lists.
This outline is also available in PDF.
Held: Wednesday, 13 September 2006
Summary: Today we continue our consideration of the process of recursion.
Related Pages:
Notes:
Overview:
and
, or
,
if
, and cond
, follow the evaluation rules
for that operation.
(define double (lambda (x) (+ x x))) (define a 5)
(double (double (* 7 (+ 1 a))))
(double (* 7 (+ 1 a)))
(* 7 (+ 1 a))
.
7
and (+ 1 a)
.
7
is a primitive value, so we're done with it.
(+ 1 a)
is a procedure application, so we evaluate its
parameters.
1
and a
.
1
is a primitive value, so we're done with it.
a
is the name for 5
, so we use that.
(+ 1 5)
. Since +
is a builtin operation, we do what it's supposed to do, and the value
of this subexpression is 6
.
(* 7 6)
. Again, we rely
on the builtin operation, and get 42
for this
subexpression.
(double 42)
. This time,
we have a userdefined operation, so we plug in 42
for
x
in the body, and get (+ 42 42)
.
84
.
(double 84)
. This is left
as an exercise for the reader.
sum
, let us consider a variant in which we compute
a similar value, but using subtraction rather than addition.
(define difference (lambda (numbers) (if (null? numbers) 0 ( (car numbers) (difference (cdr numbers)))))) (define newdifference (lambda (numbers) (newdifferencehelper (car numbers) (cdr numbers)))) (define newdifferencehelper (lambda (differencesofar remaining) (if (null? remaining) differencesofar (newdifferencehelper ( differencesofar (car remaining)) (cdr remaining)))))
Back to Recursion. On to Recursion with Lists.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
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 Thu Nov 30 21:43:23 2006.
The source to the document was last modified on Mon Sep 4 08:43:33 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Outlines/outline.12.html
.
You may wish to validate this document's HTML ; ;
Samuel A. Rebelsky, rebelsky@grinnell.eduhttp://creativecommons.org/licenses/bync/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.