Computer Science Fundamentals (CS153 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]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Back to Vectors. On to More Higher-Order Procedures.
Held: Monday, 17 February 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.
(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))
Back to Vectors. On to More Higher-Order Procedures.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[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:20:32 2003.
The source to the document was last modified on Thu Jan 16 15:16:12 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Outlines/outline.17.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby