有了"尾递归"的概念,是不是就不需要有循环了?

erqerq126 2011-02-04 07:13:45
如题,谢谢!
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
baihacker 2011-02-05
  • 打赏
  • 举报
回复
1.尾递归是一种很容易改成循环的递归,并不是所有的递归都是尾递归啊。
2.可以看看纯函数式编程的语言,里面没有循环。
3.可以看看有关计算模型,可计算性等方面的资料。
4.针对函数式语言的编译器,对递归的优化是灰常强大的。
5.
引自:http://en.wikipedia.org/wiki/Tail_Recursion
From Wikipedia, the free encyclopedia (Redirected from Tail Recursion)
Jump to: navigation, search
In computer science, a tail call is a subroutine call producing a return value, which is then immediately returned by the calling procedure. The call site is then said to be in tail position, i.e. at the end of the calling procedure. If a subroutine performs a tail call to itself, it is called tail recursive. This is a special case of recursion.

Tail calls are significant because they can be implemented without consuming space on the call stack, because the call can replace the stack frame of the current procedure with the one of the newly called procedure. To do so, it suffices to adjust the subroutine arguments and then jump to the called subroutine. Producing such code instead of a standard call sequence is called tail call elimination (TCE).

Traditionally, tail call elimination is optional, and it can also be called tail call optimization (TCO). However, in functional programming languages, tail call elimination is often guaranteed by the language standard, and this guarantee allows using recursion, in particular tail recursion, in place of loops. In such cases, it is not correct to refer to it as an optimization, even if it is customary practice.
rushman 2011-02-05
  • 打赏
  • 举报
回复
不论怎么样,都不要做这样的总结——轻易的排除某种可能性!
iambic 2011-02-05
  • 打赏
  • 举报
回复
递归是概念,尾递归是实现,什么“尾递归概念”,看着别扭。有些语言就没有循环语句,流行的比如Erlang。
ffjj56 2011-02-05
  • 打赏
  • 举报
回复
call的速度怎么能与jmp比呢?
gbb21 2011-02-05
  • 打赏
  • 举报
回复
[Quote=引用楼主 erqerq126 的回复:]
如题,谢谢!
[/Quote]
是的,请参见conitinution ...
jixingzhong 2011-02-05
  • 打赏
  • 举报
回复
逻辑上可以实现。

但是还需要考虑效率问题,包括资源和性能。
shiweifu 2011-02-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhangsongcui 的回复:]

这怎么可能?
call的速度怎么能与jmp比呢?
[/Quote]

递归开销很大,而且有些程序逻辑上递归会更复杂
zhangsongcui 2011-02-04
  • 打赏
  • 举报
回复
这怎么可能?
call的速度怎么能与jmp比呢?

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧