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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
回答2:
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>)