Why are the 'context' and 'object' functions in Rebol different, but essentially the same?

限于喜欢 提交于 2019-12-05 17:05:14

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!