Fundamentals of Computer Science I (CS151.01 2006F)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
Back to Introduction to Local Bindings. On to Discussion of Exam 1.
This outline is also available in PDF.
Held: Friday, 29 September 2006
Summary: Today we consider techniques for defining local procedures, procedures that are only available to select other procedures.
Related Pages:
Due
Assignments
Notes:
Installing Linux.
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 Introduction to Local Bindings. On to Discussion of Exam 1.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
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 Nov 30 21:43:26 2006.
The source to the document was last modified on Mon Sep 4 08:43:33 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Outlines/outline.21.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.