Fundamentals of Computer Science I (CS151.02 2007S)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
Back to Unit Testing. On to Analyzing Procedures.
This outline is also available in PDF.
Held: Wednesday, February 21, 2007
Summary: Today we consider techniques for defining local procedures, procedures that are only available to select other procedures.
Related Pages:
Notes:
Overview:
let
and let*
.
let
nor let*
works for recursive procedures.
letrec
.
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 Unit Testing. On to Analyzing Procedures.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
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 Thu Sep 13 20:54:44 2007.
The source to the document was last modified on Mon Feb 19 22:15:57 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007S/Outlines/outline.19.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.