gpt4 book ai didi

oop - 为什么称为“开放(或封闭)递归?”

转载 作者:行者123 更新时间:2023-12-01 20:22:58 27 4
gpt4 key购买 nike

我找到了一些关于开放/封闭递归的解释,但我不明白为什么定义中包含“递归”一词,或者它与动态/静态调度相比如何。我找到的解释中有:

Open recursion. Another handy feature offered by most languages with objects and classes is the ability for one method body to invoke another method of the same object via a special variable called self or, in some languages, this. The special behavior of self is that it is late-bound, allowing a method defined in one class to invoke another method that is defined later, in some subclass of the first. [Ralf Hinze]

...或Wikipedia :

The dispatch semantics of this, namely that method calls on this are dynamically dispatched, is known as open recursion, and means that these methods can be overridden by derived classes or objects. By contrast, direct named recursion or anonymous recursion of a function uses closed recursion, with early binding.

我还阅读了 StackOverflow 问题:What is open recursion?

但我不明白为什么用“递归”这个词来定义。当然,如果通过执行...方法递归调用来使用“开放递归”,则可能会导致有趣(或危险)的副作用。但这些定义并没有直接考虑方法/函数递归调用(除了维基百科定义中的“封闭递归”,但这听起来很奇怪,因为“开放递归”并不指递归调用)。

你知道定义中为什么有“递归”这个词吗?是因为它基于我不知道的另一个计算机科学定义吗?仅仅说“动态调度”还不够吗?

最佳答案

我试图在这里开始写一个答案,然后最终写了一个entire blog post关于它。 TL;DR 是:

So, if you compare a real object-oriented language to a simpler language with just structures and functions, the differences are:

  • All of the methods can see and call each other. The order they are defined doesn’t matter since their definitions are “simultaneous” or mutually recursive.
  • The base methods have access to the derived receiver object (i.e. this or self in other languages) so they don’t close over just each other. They are open to overridden methods.

Thus: open recursion.

关于oop - 为什么称为“开放(或封闭)递归?”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17803621/

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