This outline is also available in PDF.
Held: Tuesday, 27 October 2009
Summary: We explore why and how one writes local recursive procedures.
Iowa's Great Contribution to Programming: The Husk-and-Kernel approach
let*works for recursive procedures.
letrecexpression has the format
(letrec ((name1 exp1) (name2 exp2) ... (namen expn)) body)
letrecis evaluated using the following series of steps.
nameninto the binding table. (Note that no corresponding values are entered.)
expn, giving you results
resultifor each reasonable i.
let, except that the order of entry into the binding table is changed.
letis somewhat stranger, but is handy for some problems.
lethas the format
(let name ((param1 exp1) (param2 exp2) ... (paramn expn)) body)
(letrec ((name (lambda (param1 ... paramn ) body))) (name val1 ... valn))
(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-kernela 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))))))
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 Fri Dec 11 09:38:46 2009.
The source to the document was last modified on Fri Aug 21 17:03:06 2009.
This document may be found at
You may wish to validate this document's HTML ; ;Samuel A. Rebelsky, email@example.com
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.