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 built-in operation, we do what it's supposed to do, and the value
of this sub-expression is 6.
(* 7 6). Again, we rely
on the built-in operation, and get 42 for this
subexpression.
(double 42). This time,
we have a user-defined 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 new-difference
(lambda (numbers)
(new-difference-helper (car numbers) (cdr numbers))))
(define new-difference-helper
(lambda (difference-so-far remaining)
(if (null? remaining)
difference-so-far
(new-difference-helper (- difference-so-far (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
;
;
http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.