CS151.02 2010S Functional Problem Solving
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
-
[Assignment]
[Quiz]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Quizzes]
[Readings]
References:
[A-Z]
[By Topic]
-
[Scheme Report (R5RS)]
[R6RS]
[TSPL4]
Related Courses:
[CSC151.02 2009S (Weinman)]
[CSC151.02 2009S (Davis)]
[CSC151 2009F (Rebelsky)]
Misc:
[SamR]
[MediaScript]
[GIMP]
Back to Preconditions, Revisited. On to Randomized (Unpredictable) Drawing.
This outline is also available in PDF.
Held: Wednesday, March 17, 2010
Summary: We explore why and how one writes local recursive procedures.
Related Pages:
Notes:
Overview:
letrec.reverse.Iowa's Great Contribution to Programming: The Husk-and-Kernel approach
let and let*.
let nor let* works for recursive procedures.
letrec.
let called named let.
letrecletrec expression has the format
(letrec ((name1 exp1)
(name2 exp2)
...
(namen expn))
body)
letrec is evaluated using the following series
of steps.
name1 through
namen into the binding table.
(Note that no corresponding values are entered.)
exp1 through
expn, giving you results
result1 through
resultn.
namei and
resulti for each
reasonable i.
let, except
that the order of entry into the binding table is changed.
letlet is somewhat stranger, but is handy for
some problems.
let has the format
(let name ((param1 exp1) (param2 exp2) ... (paramn expn)) body)
param1 ...
paramn
and body body.
name.
exp1 through
expn .
(letrec ((name (lambda (param1 ...
paramn
)
body)))
(name val1 ... valn))
reverse.
(define reverse
(lambda (lst)
(reverse-kernel lst null)))
(define reverse-kernel
(lambda (remaining so-far)
(if (null? remaining)
so-far
(reverse-kernel (cdr remaining) (cons (car remaining) so-far)))))
reverse-kernel a local procedure.
(define reverse
(letrec ((kernel
(lambda (remaining so-far)
(if (null? remaining)
so-far
(kernel (cdr remaining) (cons (car remaining) so-far))))))
(lambda (lst)
(kernel lst null))))
create a kernel and call itis so common that the named let exists simply as a way to write that more concisely.
(define reverse
(lambda (lst)
(let kernel ((remaining lst)
(so-far null))
(if (null? remaining)
so-far
(kernel (cdr remaining) (cons (car remaining) so-far))))))
Back to Preconditions, Revisited. On to Randomized (Unpredictable) Drawing.
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
-
[Assignment]
[Quiz]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Quizzes]
[Readings]
References:
[A-Z]
[By Topic]
-
[Scheme Report (R5RS)]
[R6RS]
[TSPL4]
Related Courses:
[CSC151.02 2009S (Weinman)]
[CSC151.02 2009S (Davis)]
[CSC151 2009F (Rebelsky)]
Misc:
[SamR]
[MediaScript]
[GIMP]
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 11 09:03:12 2010.
The source to the document was last modified on Thu Jan 21 13:05:15 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2010S/Outlines/outline.31.html.
You may wish to
validate this document's HTML
;
;
http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.