Fundamentals of Computer Science I: Media Computing (CS151.01 2008S)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Readings]
References:
[AZ]
[Primary]
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2008S (Davis)]
[CSC151 2007F (Rebelsky)]
[CSC151 2007S (Rebelsky)]
[CSCS151 2005S (Stone)]
Misc:
[SamR]
[DrFu]
[GIMP]
[DrScheme]
Back to Preconditions, Revisited. On to Numeric Recursion.
This outline is also available in PDF.
Held: Monday, 10 March 2008
Summary: We explore why and how one writes local recursive procedures.
Related Pages:
Notes:
Overview:
letrec
.reverse
.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
(which I hope you recall from the exam).
(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 Numeric Recursion.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Readings]
References:
[AZ]
[Primary]
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2008S (Davis)]
[CSC151 2007F (Rebelsky)]
[CSC151 2007S (Rebelsky)]
[CSCS151 2005S (Stone)]
Misc:
[SamR]
[DrFu]
[GIMP]
[DrScheme]
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 Apr 15 23:11:40 2008.
The source to the document was last modified on Thu Jan 17 16:44:15 2008.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2008S/Outlines/outline.28.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.