Type | Wish | Status | dismissed | Date | 25-Mar-2010 10:30 |
---|---|---|---|---|---|
Version | alpha 97 | Category | Native | Submitted by | BrianH |
Platform | All | Severity | minor | Priority | normal |
Summary | BIND /self option |
---|---|
Description |
BIND block! currently does a trick where the hidden 'self field of the context is bound anyways. But there are times that we don't want to do this, when we don't want any existing binding of 'self overriden in the code block. Look at #447 and #1529 for native cases of this concern. However, the solution to #447 proves that the 'self trick can be turned off for native code as needed: Closures no longer bind 'self in their code block when they are created. I would like to make that option visible, usable by mezzanine code through the BIND function. A BIND/self option would turn on the 'self binding trick, and the new default behavior without /self would be to not make the hidden 'self field visible. The rest of what BIND does would be the same. This ticket (suggested by Ladislav) is the opposite of #1543. If that ticket is accepted, this one should be dismissed, and vice-versa. |
Example code |
; Current behavior >> same? 'self first bind [self] context [] == false ; Desired behavior >> same? 'self first bind [self] context [] == true >> same? 'self first bind/self [self] context [] == false |
Assigned to | n/a | Fixed in | - | Last Update | 2-May-2010 20:46 |
---|
Comments | |
---|---|
(0002126)
BrianH 25-Mar-2010 10:38 |
Note that if this proposal is accepted instead of #1543, all mezzanine code that currently calls BIND directly would need the /self option. This means, at least, DO, LOAD, DO-NEEDS, INTERN, INSERT and MAKE-MODULE. |
(0002127)
abolka 25-Mar-2010 15:26 |
I'd prefer this /self variant over /no-self as proposed in #1543, as I think special self handling is not desirable in the vast majority of ("user-level") cases. Further, the positive refinement reads better than the negative version, in my opinion.
So, +1 for this variant from me. |
(0002129)
BrianH 25-Mar-2010 21:11 |
I prefer it too. The thing I like the most is that the 'self trick is a little more advanced than not doing it, especially for code that calls BIND explicitly. Doing the simple thing by default is the REBOL way. And this means that only users who know about 'self would be using it in any explicit way. And the advanced code that is called implicitly can use /self where appropriate.
The downside (if you can call it that, see #666) is that BIND will be even less compatible with R2 than it is now. Binding is an area where compatibility between R2 and R3 is even less likely than it is anywhere else, so this is not really a surprise (or necessarily a problem). |
(0002132)
BrianH 25-Mar-2010 22:32 |
One trick though is that we would like to keep the current interaction between overrides of 'self and hiding them. To illustrate:
; Current behavior: >> a: construct [] == make object! [ ] >> append a [self: 1] == make object! [ self: 1 ] >> do bind [self] a == 1 >> protect/hide in a 'self == self >> do bind [self] a == make object! [ ] >> same? a do bind [self] a == true With this proposal we want the same thing to happen with BIND/self instead. |
(0002153)
BrianH 30-Mar-2010 02:47 |
And additional advantage to BIND/self would be that we could have BIND/self trigger an error if attempting to bind to a function! word. This would be greatly preferred to the current behavior:
>> same? self do func [a] [do bind [self] 'a] 1 == true Having 'self not be overriden here is currently a gotcha with function bindings (and arguably a major problem, though just a gotcha because it's documented). It would be better to throw an error in the BIND/self case, and not unhide 'self for the default case. |
(0002268)
BrianH 28-Apr-2010 22:07 |
Here are tests to illustrate the practical effects of this proposal, taken from http://www.rebol.net/cgi-bin/r3blog.r?view=0312#comments
ob: object [] print not same? ob do bind [self] ob print not same? ob do in ob [self] print same? ob do bind/self [self] ob ob: object [f: func [/x] [do bind/copy [self] 'x]] print same? ob ob/f ob: object [f: func [/x] [do bind/copy/self [self] 'x]] print error? try [ob/f] ob: repeat x 1 [bind? 'x] print 1 = ob/x print not same? ob do bind [self] ob print not same? ob do in ob [self] print same? ob do bind/self [self] ob ob: repeat self 1 [bind? 'self] print 1 = attempt [ob/self] print not same? ob do bind [self] ob print not same? ob do in ob [self] print error? try [do bind/self [self] ob] All print statements should print "true". The ones with ERROR? are the core of the proposal. |
(0002296)
BrianH 2-May-2010 20:45 |
Dismissed in alpha 98 in favor of #1549 |
Date | User | Field | Action | Change |
---|---|---|---|---|
2-May-2010 20:46 | BrianH | Description | Modified | - |
2-May-2010 20:46 | BrianH | Code | Modified | - |
2-May-2010 20:46 | BrianH | Status | Modified | submitted => dismissed |
2-May-2010 20:45 | BrianH | Comment : 0002296 | Added | - |
28-Apr-2010 22:07 | BrianH | Comment : 0002268 | Added | - |
30-Mar-2010 02:47 | BrianH | Comment : 0002153 | Added | - |
26-Mar-2010 01:01 | BrianH | Comment : 0002129 | Modified | - |
25-Mar-2010 22:32 | BrianH | Comment : 0002132 | Added | - |
25-Mar-2010 21:14 | BrianH | Comment : 0002129 | Modified | - |
25-Mar-2010 21:11 | BrianH | Comment : 0002129 | Added | - |
25-Mar-2010 15:26 | abolka | Comment : 0002127 | Added | - |
25-Mar-2010 10:38 | BrianH | Comment : 0002126 | Modified | - |
25-Mar-2010 10:38 | BrianH | Comment : 0002126 | Added | - |
25-Mar-2010 10:30 | BrianH | Ticket | Added | - |