为什么将其称为“开放(或封闭)递归"? [英] Why is it called "open (or closed) recursion?

查看:125
本文介绍了为什么将其称为“开放(或封闭)递归"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些关于打开/关闭递归的解释,但是我不明白为什么定义中包含递归"一词,或者它与动态/静态分派相比如何.在我找到的解释中,有:

I found some explanations of open/closed recursion, but I do not understand why the definition contains the word "recursion", or how it compares with dynamic/static dispatching. Among the explanations I found, there are:

打开递归.大多数人提供的另一个便捷功能 具有对象和类的语言是一种方法的能力 主体通过特殊方法调用同一对象的另一种方法 变量称为self,或者在某些语言中为this.特别的 自我的行为是晚绑定的,允许定义方法 在一个类中调用稍后定义的另一种方法,在 第一个的子类. [ Ralf Hinze ]

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]

...或维基百科:

this的调度语义,即动态调用此方法的方法,称为 open递归,这意味着派生类或对象可以覆盖这些方法.相比之下,函数的直接命名递归或匿名递归使用具有早期绑定的封闭式递归.

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问题:什么是开放递归?

I also read the StackOverflow question: What is open recursion?

但是我不明白为什么将递归"一词用于定义.当然,如果通过执行...方法递归调用来使用开放递归",则可能导致有趣的(或危险的)副作用.但是这些定义并未直接考虑方法/函数的递归调用(在Wikipedia定义中采用封闭式递归",但是听起来很奇怪,因为开放式递归"并不涉及递归调用).

But I do not understand why the word "recursion" is used for the definition. Of course, it can lead to interesting (or dangerous) side-effect if one uses "open recursion" by doing... a method recursion call. But the definitions do not take method/function recursive call directly into account (appart the "closed recursion" in the Wikipedia definition, but it sounds strange since "open recursion" does not refer to recursive call).

您知道定义中为什么有递归"一词吗?是因为它基于我不知道的另一种计算机科学定义吗?仅仅说动态派遣"还不够吗?

Do you know why there is the word "recursion" in the definition? Is it because it is based on another computer science definition that I am not aware of? Should simply saying "dynamic dispatch" not be enough?

推荐答案

我试图在这里开始写答案,然后最终写了

I tried to start writing an answer here and then ended up writing an entire blog post about it. The TL;DR is:

因此,如果将真正的面向对象语言与仅具有结构和功能的简单语言进行比较,则差异是:

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

  • 所有方法都可以相互查看和调用.定义顺序无关紧要,因为它们的定义是同时的"或相互递归.
  • 基本方法可以访问派生的接收者对象(即其他语言中的this或self),因此它们不会彼此靠近.它们是 open 可以覆盖的方法.
  • 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.

因此:打开递归.

这篇关于为什么将其称为“开放(或封闭)递归"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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