Fundamentals of Computer Science 1 (CS151 2003S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Scheme Reference]
[Scheme Report]
[CS151 2003S Gum]
[CS151 2002F]
[CS151 History]
[SamR]
Back to Deep Recursion. On to Procedures as Values, Continued.
Held: Tuesday, 11 March 2003
Summary: Today we investigate higher-order procedures; procedures that take other procedures as parameters or return procedures as values. Higher-order procedures are one of the most important design techniques in the functional paradigm (nearly as important as recursion).
Related Pages:
Assignments
Notes:
Overview:
map
and apply
.rowsof the class to write three related:
(map proc lst)
-- build a new list by applying
proc
to each element of lst
.
(apply proc lst)
-- call proc
on the arguments
given by lst
(define square-vals (lambda (lst) (map (lambda (x) (* x x)) lst)))
(define sum (lambda (lst) (apply + lst)))
apply to alldesign pattern is so common that Scheme includes it as a built-in procedure (called
map
).
(map proc lst)
: what we just wrote.
(apply proc lst)
: a way to treat
the elements of lst as parameters to proc.
(define sum (lambda (lst) (apply + lst)))
> (let ((square (lambda (x) (* x x)))) (map square (list 1 2 3 4)))
square
is
another name for (lambda (x) (* x x))
and then uses
that name.
(map (lambda (x) (* x x)) '(1 2 3 4))
(lambda (arguments) body)
(define make-adder (lambda (n) (lambda (v) (+ n v))))
some numberto its parameter.
(lambda (v) (+ some-number v))
Thursday, 16 January 2003 [Samuel A. Rebelsky]
Tuesday, 11 March 2003 [Samuel A. Rebelsky]
Back to Deep Recursion. On to Procedures as Values, Continued.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Scheme Reference]
[Scheme Report]
[CS151 2003S Gum]
[CS151 2002F]
[CS151 History]
[SamR]
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 May 6 09:30:01 2003.
The source to the document was last modified on Tue Mar 11 08:14:18 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003S/Outlines/outline.30.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby