我在这个计划评估中做错了什么?
评估:
((((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4) 5)
这就是我所做的:
评估
((((lambda (x) (lambda (y) (lambda (x) (+ xy)))) 3) 4) 5)
- 评估
5 -> 5
- 评估
评估
(((lambda (x) (lambda (y) (lambda (x) (+ xy)))) 3) 4)
- 评估
4 -> 4
- 评估
评估
((lambda (x) (lambda (y) (lambda (x) (+ xy)))) 3)
- 评估
3 -> 3
- 评估
(lambda (x) (lambda (y) (lambda (x) (+ xy))))
->(lambda (x) (lambda (y) (lambda (x) (+ xy))))
应用
(lambda (x) (lambda (y) (lambda (x) ) (+ xy))))
到3
替换
3
->x
in(lambda (y) (lambda (x) (+ xy))
(lambda (y) (lambda (x) (+ 3 y))
计算
(lambda (y) (lambda (x) (+ 3 y)) -> (lambda (y) (lambda (x) (+ 3 y))
< /p>将 (lambda (y) (lambda (x) (+ 3 y))
应用于4
替换
4 -> y
in(lambda (y) (lambda (x) (+ 3 y))
(lambda (y) (+ 3 4))
评估
(lambda (y) (+ 3 4)) -> (拉姆达(y)(7))
- 替换
5
-> ?
- 替换
然后我就卡住了。
Evaluate:
((((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4) 5)
This is what I did:
evaluate
((((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4) 5)
- evaluate
5 -> 5
- evaluate
evaluate
(((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4)
- evaluate
4 -> 4
- evaluate
evaluate
((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3)
- evaluate
3 -> 3
- evaluate
(lambda (x) (lambda (y) (lambda (x) (+ x y))))
->(lambda (x) (lambda (y) (lambda (x) (+ x y))))
apply
(lambda (x) (lambda (y) (lambda (x) (+ x y))))
to3
substitute
3
->x
in(lambda (y) (lambda (x) (+ x y))
(lambda (y) (lambda (x) (+ 3 y))
evaluate
(lambda (y) (lambda (x) (+ 3 y)) -> (lambda (y) (lambda (x) (+ 3 y))
apply (lambda (y) (lambda (x) (+ 3 y))
to4
subsitute
4 -> y
in(lambda (y) (lambda (x) (+ 3 y))
(lambda (y) (+ 3 4))
evaluate
(lambda (y) (+ 3 4)) -> (lambda (y) (7))
- subsitute
5
-> ?
- subsitute
And then I'm stuck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您将其分解为单独的“定义”程序。
现在调用
(((part2 3) 4) 5) =>; 9
I suggest you break this down into individual 'defined' procedures.
Now call
(((part2 3) 4) 5) => 9
首先,这是错误的。 您不必将所有出现的
x
替换为3
,而只能替换免费的x
。 您在此处替换的x
受内部 lambda 表达式约束,因此不是自由的。其次,用从未使用过的变量替换值并没有什么问题,因此在
(+ 3 4)
中用5
替换y
就可以了并产生(+ 3 4)
。First, this is wrong. You don't substitute
3
for all occurrences ofx
, only for the free ones. Thex
you're replacing here is bound by the inner lambda expression and therefore not free.Second, there's nothing wrong with substituting a value for a variable that's never used, so substituting
5
fory
in(+ 3 4)
is fine and yields(+ 3 4)
.你的第一个替换是错误的;
(+ xy)
中的x
由最内层的lambda
绑定,而不是最外层。 这意味着替换的结果只是(lambda (y) (lambda (x) (+ xy)))
。3
已“丢失”。 (也许您应该查找替换规则并逐步应用它们,以便更好地掌握它。)无论如何,要完成您仍然可以应用
(lambda (y) (7))
(或(lambda (y) (+ 4 x))
如果您解决了上述问题)到5
以获得7
(或(+ 4 5)
其计算结果为9
)。Your first substitution is wrong; the
x
in(+ x y)
is bound by the innermostlambda
, not the outermost. This means the result of that substitution is just(lambda (y) (lambda (x) (+ x y)))
. The3
is "lost". (Perhaps you should look up the substitution rules and apply them step by step to getter a better grasp of it.)Regardless of this, to finish you can still apply
(lambda (y) (7))
(or(lambda (y) (+ 4 x))
if you fix the above) to5
to get7
(or(+ 4 5)
which evaluates to9
).