向我解释尾调用优化有什么大不了的,以及为什么 Python 需要它 [英] Explain to me what the big deal with tail call optimization is and why Python needs it

查看:30
本文介绍了向我解释尾调用优化有什么大不了的,以及为什么 Python 需要它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,关于 Python 是否需要尾调用优化的问题引起了很大争议.当有人向 Guido 发送了一份 SICP 因为他没有明白".我和圭多在同一条船上.我理解尾调用优化的概念.我实在想不出为什么 Python 真的需要它.

So apparently, there's been a big brouhaha over whether or not Python needs tail call optimization. This came to a head when someone shipped Guido a copy of SICP because he didn't "get it." I'm in the same boat as Guido. I understand the concept of tail call optimization. I just can't think of any reason why Python really needs it.

为了让我更容易理解,谁能给我一段代码,使用 TCO 可以大大简化?

To make this easier for me to understand, could someone give me a snippet of code that would be greatly simplified using TCO?

推荐答案

就我个人而言,我非常重视尾调用优化;但主要是因为它使递归与迭代一样有效(或使迭代成为递归的子集).在极简语言中,您可以在不牺牲性能的情况下获得强大的表达能力.

Personally, I put great value on tail call optimization; but mainly because it makes recursion as efficient as iteration (or makes iteration a subset of recursion). In minimalistic languages you get huge expressive power without sacrificing performance.

在实用"语言(如 Python)中,OTOH,对于几乎所有可以想象的情况,您通常都有很多其他结构,因此它不那么重要.拥有它总是一件好事,当然,允许出现不可预见的情况.

In a 'practical' language (like Python), OTOH, you usually have a lot of other constructions for almost every situation imaginable, so it's less critical. It is always a good thing to have, to allow for unforeseen situations, of course.

就我个人而言,我非常重视尾调用优化;但主要是因为它使递归与迭代一样有效(或使迭代成为递归的子集).在极简语言中,您可以在不牺牲性能的情况下获得强大的表达能力.

Personally, I put great value on tail call optimization; but mainly because it makes recursion as efficient as iteration (or makes iteration a subset of recursion). In minimalistic languages you get huge expressive power without sacrificing performance.

在实用"语言(如 Python)中,OTOH,对于几乎所有可以想象的情况,您通常都有很多其他结构,因此它不那么重要.拥有它总是一件好事,当然,允许出现不可预见的情况.

In a 'practical' language (like Python), OTOH, you usually have a lot of other constructions for almost every situation imaginable, so it's less critical. It is always a good thing to have, to allow for unforeseen situations, of course.

这篇关于向我解释尾调用优化有什么大不了的,以及为什么 Python 需要它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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