Fundamentals of CS I (CS151 2001S) : Outlines
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Reading: Higher Order Procedures. Lab: Higher-Order Procedures. Back to Local Procedure Bindings. On to Procedures as Values, Continued.
Held Thursday, March 15, 2001
Summary
Today we investigate higher-order procedures; procedures that take other procedures as parameters or return procedures as values.
Notes
last-element
procedure from yesterday's lab. They seem to be good examples for
discussing some tradeoffs in program design.
(let ((last-element (lambda (lst)
(car (reverse lst)))))
...)
(let ((last-element (lambda (lst)
(list-ref lst (- (length lst) 1)))))
...)
(letrec ((last-element (lambda (lst)
(if (null? (cdr lst))
(car lst)
(last-element (cdr lst))))))
...)
Overview
map, apply
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))
Friday, 12 January 2001
Thursday, 15 March 2001
Back to Local Procedure Bindings. On to Procedures as Values, Continued.
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Wed May 5 12:15:03 2004.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.31.html.
You may validate
this page's HTML.
The source was last modified Thu Mar 15 08:53:21 2001.