gpt4 book ai didi

lisp - Lisp 中的递归与迭代

转载 作者:太空宇宙 更新时间:2023-11-03 19:04:14 29 4
gpt4 key购买 nike

在此站点 http://jatha.sourceforge.net/快速函数的示例是通过递归。是不是递归通常比 Lisp 中的迭代更快并且性能更好?

编辑:Lisp 是否比其他语言更优化递归?

最佳答案

这实际上取决于您所说的“Lisp”和“递归”是什么意思。

Scheme 任务 tail call optimization ,但除此之外,您受制于您的实现(以及您的 optimization settings)。

例如,如果 debug 设置高于 speed 设置,Lisp 实现可能会保持递归调用未优化,因此跟踪更有意义。您需要查阅您的实现手册以了解详细信息。

然而,这里的关键点是(SICP):

... a computer language is not just a way of getting a computer to perform operations, but rather ... it is a novel formal medium for expressing ideas about methodology

IOW,你编写的代码是供人们阅读的,而不是供计算机执行的,所以你需要更多地考虑如何清楚地表达你的算法,而不是如何编译和执行它。

关于lisp - Lisp 中的递归与迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38294190/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com