I have a scheme related question, how can we implement let* as a lambda expression. To be more precise, I am not wondering about the "regular" let, but the let with * which lets us use one let expression within another.
Asked
Active
Viewed 336 times
5
-
1check this out: http://stackoverflow.com/questions/15003518/confused-by-the-difference-between-let-and-let-in-scheme/15006018#15006018 – Will Ness May 22 '13 at 20:14
2 Answers
5
The let*
form is a series of nested lambda
s. For example, this:
(let* ((a 10)
(b (+ 10 a)))
(+ a b))
Is equivalent to this:
((lambda (a)
((lambda (b)
(+ a b))
(+ 10 a)))
10)

Óscar López
- 232,561
- 37
- 312
- 386
4
Since you are not wondering about the 'regular' let
, if a let*
can be converted into let
then you will have your answer. Therefore know that:
(let* ((a ...) (b ...) (c ...)) body ...)
is equivalent to:
(let ((a ...))
(let ((b ...))
(let ((c ...))
body ...)))
(see R5RS, page 44, (define-syntax let* ...)
). Now, given this, and knowledge that:
(let ((a ...)) body ...)
is equivalent to:
((lambda (a) body ...) ...)
the 'expansion' of the let*
that I showed above becomes:
((lambda (a)
((lambda (b)
((lambda (c)
body ...)
<c-init>))
<b-init>))
<a-init>)

GoZoner
- 67,920
- 20
- 95
- 145