为什么Rebol中的“上下文”和“对象”函数不同,但本质上是一样的? [英] Why are the 'context' and 'object' functions in Rebol different, but essentially the same?

查看:211
本文介绍了为什么Rebol中的“上下文”和“对象”函数不同,但本质上是一样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一方面,我们有:

>> source object
object: make function! [[
    "Defines a unique object."
    blk [block!] "Object words and values."
][
    make object! append blk none
]]

对于上下文我们看到:

>> source context
context: make function! [[
    "Defines a unique object."
    blk [block!] "Object words and values."
][
    make object! blk
]]

因此,对于 object 对象是从添加了 none 的块构造的。这不会改变长度,或者,据我所知,添加任何东西。另一方面,使用 context ,对象使用传入的块来构造。

So, for object the object is constructed from a block to which none has been appended. This doesn't change the length, or, to my knowledge, add anything. With context, on the other hand, the object is constructed with the passed-in block, as is.

为什么差别和为什么,例如,不能上下文只是<$ c $的别名c> object 。

Why the difference and why, for example, couldn't context just be an alias for object.

推荐答案

向后兼容性。我们有一个上下文函数已经在Rebol工作了一个特定的方式(不初始化变量),但我们需要一个函数初始化变量为无,作为一个方便的功能,当创建对象作为数据结构而不是代码容器。

Backwards compatibility. We had a context function already in Rebol that worked a particular way (not initializing variables), but we needed a function that initialized variables to none, as a convenience function when creating objects as data structures rather than as code containers.

因为这是类型名称,所以调用它 object 是有意义的,因为context对于具有上下文敏感语义的语言中的对象的不良名称(对于词语上下文的更适当的含义)。它真的导致一些混乱的对话。由于R3现在有模块,以前的上下文函数的大多数使用被模块更好地覆盖。保持上下文基本上是为了向后兼容。

It made sense to call it object since that is the type name, and since "context" is actually kind of a bad name for objects in a language with context-sensitive semantics (for a more appropriate meaning of the word "context"). It really leads to some confusing conversations. Since R3 has modules now, most of the previous uses of the context function are covered better by modules. Keeping context at all is mostly for backwards compatibility.

当前对象函数是一个更好的类型构造包装器的占位符,我们还没有想到。我们需要类似的东西,但它可能需要微妙的变化,我们会发现更多的使用。一方面,它修改其spec块的事实,使得它不是非常安全的递归或并发。如果改进了它,它可能会最终作为一个本机,或者如果这是一个更好的方法,或者作为一个构造选项。

The current object function is pretty much a placeholder for a better type construction wrapper that we haven't thought up yet. We need something like it, but there may be subtle changes in its behavior needed that we'll discover with more use. For one thing, the fact that it modifies its spec block makes it not very safe for recursion or concurrency. It will likely end up as a native if that improves it, or maybe as a construct option if that turns out to be a better approach.

有一件事是成功的,就是使用没有感叹号的类型名作为类型构造函数的名称。我们改变了 map 也是这样,我们可能最终为其他类型添加类似的构造函数,尽管大多数需要它们已经有它们。

One thing that did turn out to be a win is the practice of using the type name without the exclamation point as the name of a type construction function. We changed map to be that as well, and we may end up adding similar constructors for other types, though most that need them have them already.

这篇关于为什么Rebol中的“上下文”和“对象”函数不同,但本质上是一样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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