Fundamentals of Computer Science I (CS151.02 2007S)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
Back to Recursion. On to Recursion with Lists.
This outline is also available in PDF.
Held: Friday, February 9, 2007
Summary: Today we continue our consideration of the process of recursion.
Related Pages:
Due
Notes:
Overview:
I included the following notes in previous offerings of this course. I will cover them if (or when) questions suggest that such coverage is necessary.
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]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
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 Sep 13 20:54:41 2007.
The source to the document was last modified on Thu Jan 18 12:30:12 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007S/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.