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:
[AZ]
[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 HuskandKernel approach
let
and let*
.
let
nor let*
works for recursive procedures.
letrec
.
let
called named let.
letrec
letrec
expression has the format
(letrec ((name_{1} exp_{1}) (name_{2} exp_{2}) ... (name_{n} exp_{n})) body)
letrec
is evaluated using the following series
of steps.
name_{1}
through
name_{n}
into the binding table.
(Note that no corresponding values are entered.)
exp_{1}
through
exp_{n}
, giving you results
result_{1}
through
result_{n}
.
name_{i}
and
result_{i}
for each
reasonable i.
let
, except
that the order of entry into the binding table is changed.
let
let
is somewhat stranger, but is handy for
some problems.
let
has the format
(let name ((param_{1} exp_{1}) (param_{2} exp_{2}) ... (param_{n} exp_{n})) body)
param_{1}
...
param_{n}
and body body
.
name
.
exp_{1}
through
exp_{n}
.
(letrec ((name (lambda (param_{1} ... param_{n} ) body))) (name val_{1} ... val_{n}))
reverse
.
(define reverse (lambda (lst) (reversekernel lst null))) (define reversekernel (lambda (remaining sofar) (if (null? remaining) sofar (reversekernel (cdr remaining) (cons (car remaining) sofar)))))
reversekernel
a local procedure.
(define reverse (letrec ((kernel (lambda (remaining sofar) (if (null? remaining) sofar (kernel (cdr remaining) (cons (car remaining) sofar)))))) (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) (sofar null)) (if (null? remaining) sofar (kernel (cdr remaining) (cons (car remaining) sofar))))))
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:
[AZ]
[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 ; ;
Samuel A. Rebelsky, rebelsky@grinnell.eduhttp://creativecommons.org/licenses/bync/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.