REBOL3 tracker
  0.9.12 beta
Ticket #0002118 User: anonymous

Project:



rss
TypeWish Statusreviewed Date28-Feb-2014 00:42
Versionr3 master CategoryMezzanine Submitted byBrianH
PlatformAll Severityminor Prioritynormal

Summary Replace CONTEXT function(s) with OBJECT
Description OBJECT was originally added to make code like this work:
>> object [a: b:]
== make object! [
a: none
b: none
]

Just a simple way to declare objects that are used as data structures, rather than code organization. The way it does this is to modify the spec (appending none) and calling MAKE OBJECT!, which *again* modifies the spec.

However, CONSTRUCT does the same thing:
>> construct [a: b:]
== make object! [
a: none
b: none
]

And it does it without modifying the spec (making it safe to reuse), and is native, so it's generally a better choice to use in these cases.

But then we have another problem, which is that the CONTEXT function is really badly named, since it doesn't really have anything to do with contexts. The Rebol-jargon term "context" is just the worst term to use for the referred-to concept, when dealing with a language that has real context-sensitive semantics (dialects). We would all benefit from that function going away, eventually.

And in a weird turn, there is a limited native CONTEXT function used during the bootstrap process, which is replaced at some point with the current mezzanine CONTEXT. Didn't see that coming.

So my request is that both the native and mezzanine CONTEXT be renamed to OBJECT, with their current behavior. CONTEXT would be left as a value alias of OBJECT for backwards compatibility, and marked as deprecated in the source, like FUNCT. See #2123 for that.

At some point soon we should unify the native and the mezzanine, since the single parameter means we can make it more optimized than MAKE OBJECT! (fewer semantic variants). Plus, the mezzanine OBJECT and the old CONTEXT are subject to #539, where the native isn't.
Example code

			

Assigned ton/a Fixed in- Last Update7-Mar-2014 07:41


Comments
(0004275)
fork
28-Feb-2014 01:44

I never understood why OBJECT [a: b:] shouldn't be an error, so definitely support it being an error.

What I thought CONTEXT was for was to create a little local scope where you wouldn't write through to the external environment. But it only works for the top level set-words you pass it, as it's just calling make object!

x: y: 10
result: context [x: 20 if true [y: 20] "something"]
print x
print y
probe result

So that outputs "10" and "20" and "make object! [x: 20]". I think that given the properties of what it does, its name is deceptive. That behavior is defined pretty much by OBJECT already.

But that does suggest what *would* be useful, which would be something that output "10" and "10" and "something". I would call that a SCOPE.

@BrianH has proposed an implementation of scope as:

scope: func [code [block!]] [do bind/copy/set code construct []]
a: 1 b: 2
probe scope [a: 10 if true [b: 20] reduce [a b]]
print [a b]

...with the caveats that it binds SELF, and that it is subject to CC#539, until some mechanism for handling RETURN and EXIT properly from this kind of construct has been decided.

In StackOverflow chat we also discussed why making CONTEXT do what I thought it did (or coming up with another word) wouldn't be generally useful. For instance:

x: y: 10
result: context [x: 20 if true [y: 20]]
print result/x
print result/y

Wanting that code to print "10" and "10" requires deep collecting. Says @BrianH: "We don't deep-collect set-words in modules either, because it hides errors and allocates unnecessary words in the module's object. Plus, most of those words get overridden by FUNCTION, CLOSURE, and nested objects anyways."

In general you don't want deep collection on entities you plan to keep around and treat like objects. It makes sense for SCOPE because it's not producing any kind of object, rather throwing the contents away when its done.

So it seems that OBJECT is "the better context", and CONTEXT can be deprecated without introducing a deep-copying variant.
(0004276)
BrianH
28-Feb-2014 03:47

See #2119 for SCOPE. SCOPE is a proposal for a function that would do what CONTEXT was used for when the result was just thrown away afterwards (common in pre-module code). SCOPE does a better and safer job of that, with deep collection of set-words, and returns the value of the last expression, making it more useful when called within other code.

With this proposed change to OBJECT and the new SCOPE function, we could deprecate CONTEXT in both of its common uses (see #2123).
(0004299)
BrianH
5-Mar-2014 00:38

Implemented in https://github.com/rebol/rebol/pull/199
(0004309)
BrianH
5-Mar-2014 06:49

It turns out that there are two CONTEXT functions, one mezzanine and one native. We should rename the native CONTEXT to OBJECT as well.

We might also consider filling in the missing functionality of the mezzanine in the native, then getting rid of the mezzanine altogether.
(0004334)
BrianH
7-Mar-2014 07:41

#2119 changed to WRAP, and the discovery of the native, mean that a new PR is needed. Back to reviewed.

Date User Field Action Change
7-Mar-2014 07:42 BrianH Comment : 0004334 Modified -
7-Mar-2014 07:42 BrianH Comment : 0004334 Modified -
7-Mar-2014 07:41 BrianH Comment : 0004334 Added -
7-Mar-2014 07:39 BrianH Status Modified pending => reviewed
7-Mar-2014 07:38 BrianH Description Modified -
7-Mar-2014 07:38 BrianH Summary Modified Make OBJECT do the same thing that CONTEXT does now => Replace CONTEXT function(s) with OBJECT
5-Mar-2014 06:49 BrianH Comment : 0004309 Added -
5-Mar-2014 03:14 BrianH Comment : 0004276 Modified -
5-Mar-2014 03:14 BrianH Description Modified -
5-Mar-2014 00:38 BrianH Comment : 0004299 Added -
5-Mar-2014 00:37 BrianH Status Modified submitted => pending
5-Mar-2014 00:37 BrianH Description Modified -
3-Mar-2014 21:20 BrianH Comment : 0004276 Modified -
3-Mar-2014 21:19 BrianH Comment : 0004276 Modified -
28-Feb-2014 03:47 BrianH Comment : 0004276 Added -
28-Feb-2014 03:38 Fork Comment : 0004275 Modified -
28-Feb-2014 02:52 Fork Comment : 0004275 Modified -
28-Feb-2014 02:29 Fork Comment : 0004275 Modified -
28-Feb-2014 01:45 Fork Comment : 0004275 Modified -
28-Feb-2014 01:44 Fork Comment : 0004275 Added -
28-Feb-2014 00:42 BrianH Ticket Added -