什么是“Lambda提升”? [英] What is "Lambda Lifting"?

查看:159
本文介绍了什么是“Lambda提升”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到这个同时通过Erlang编译器源。

I just ran into this while going through the Erlang compiler source.

我真的没有得到它。 (go figure;)),考虑到我只是意识到,有一个这样的事情5分钟前)。

I'm not really getting it. (go figure ;)), considering that I just realized that there is such a thing 5 minutes ago).

原谅我先问,不先试图理解它存在的原因。

Forgive me for asking first without first trying to understand reasons for its existence.

有一个维基百科文章关于它,但它是很神秘。

There is a wikipedia article about it, but it is pretty cryptic.

推荐答案

Lambda提升用于将闭包转换为纯函数。通过向函数传递额外的参数,可以减少其自由变量的数量。当您将lambda提升到更高和更高的范围时,您可以添加参数以适应在该范围中声明的局部变量(否则为自由变量)。一旦lambda没有自由变量,它是一个纯粹的顶级函数。

Lambda lifting is used to turn a closure into a pure function. By passing extra arguments to the function, you reduce the number of its free variables. As you "lift" the lambda into higher and higher scopes, you add arguments to accommodate the local variables declared in that scope (which would be free variables otherwise). Once the lambda has no free variables it is a pure "top level" function.

当然,你只能这样做,如果你知道所有的lambda的调用网站;换句话说,只有lambda不逃逸。

Of course you can only do this if you know all the lambda's call sites; in other words, only if the lambda does not escape.

编译器优化器的好处是可以消除闭包(函数环境)。这可能使寄存器中的参数传递,而不是堆栈(或堆)将它们分配为自由变量。

The benefit in a compiler optimizer is that closures (function environments) can be eliminated. This might make it possible to pass the arguments in registers rather than stack (or heap) allocating them as free variables.

这篇关于什么是“Lambda提升”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆