Fundamentals of CS I (CS151 2002F)
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
Back to Local Procedure Bindings. On to Procedures as Values, Continued.
Held Wednesday, October 16, 2002
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).
Associated Pages
Notes
Overview
map
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))
Thursday, 29 August 2002 [Samuel A. Rebelsky]
Tuesday, 15 October 2002 [Samuel A. Rebelsky]
Wednesday, 16 October 2002 [Samuel A. Rebelsky]
Back to Local Procedure Bindings. On to Procedures as Values, Continued.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaenous:
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]
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 Mon Dec 2 08:41:32 2002.
The source to the document was last modified on Wed Oct 16 08:39:01 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Outlines/outline.28.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby