Fundamentals of Computer Science I (CS151 2003F)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[SamR]
Back to Files. On to Procedures as Values (2).
Held: Monday, 3 November 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.filter, section, ...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))
Back to Files. On to Procedures as Values (2).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Guidelines for Lab Writeups]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Scheme Report]
[Glimmer Scheme Reference]
[CSC151.01 (Gum)]
[CSC151 2003S]
[CSC151 2002F]
[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 Dec 9 13:59:51 2003.
The source to the document was last modified on Mon Sep 1 13:30:51 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Outlines/outline.35.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby