r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3]

BrianH
24-Mar-2010
[1767]
These conversations in AltME are fun, but unless they are in blog 
comments, chat or CureCode they have no effect.
Andreas
24-Mar-2010
[1768]
Yeah, I'll add a remark later on, but I gotta run now. Take care.
Steeve
24-Mar-2010
[1769]
Carl is Altmeproof
BrianH
24-Mar-2010
[1770x3]
There's too much here. He can't afford to read all of this crap. 
He needs someone to summarize for him, and to put it somewhere that 
won't scroll off the screen.
Ok, Andreas, I'll add it for you and attribute it to you. I'm working 
on this stuff now :)
Steeve, I couldn't find your comment in CureCode bug#1529. Where 
did you post it?
Steeve
24-Mar-2010
[1773x2]
Sorry, i posted it on the blog
wrong place it seems
BrianH
24-Mar-2010
[1775x2]
Yeah, we've played out the conversation there. Too many comments 
there already.
All right, fine, I'll post your code in CureCode and attribute it 
to you. And Andreas' code too.
Gregg
24-Mar-2010
[1777]
...I cannot predict the behaviour of Bind unless I know the originator 
of the context.

 This seems like a core question to me. And while Steeve's example 
 is really neat, I wouldn't say it is REBOLish per se. BIND? doesn't 
 say a whole lot more, so I don't think either example is something 
 to hold up as a best practice. :-)


Is it by design? If so, how is it intended to be used, and how should 
it *not* be used? If not, what warnings do we need to include in 
docs?
BrianH
24-Mar-2010
[1778]
Well, when you consider that MAKE closure! also originally did the 
'self trick and now doesn't, it appears to be accidental.
BrianH
25-Mar-2010
[1779]
Comments from Steeve and Andreas posted to CureCode #1529.
Steeve
25-Mar-2010
[1780]
Thanks Brian
BrianH
25-Mar-2010
[1781]
And look at #1543 as well.
Steeve
25-Mar-2010
[1782]
bind/trick ? :)
BrianH
25-Mar-2010
[1783x2]
That's the default behavior :)
Usually we use /only to mean /no-tricks, but /only is already used 
by BIND for something else.
Steeve
25-Mar-2010
[1785]
so, bind/neat :)
BrianH
25-Mar-2010
[1786x4]
I used /no-self because it's similar to the /no-copy used elsewhere. 
Any other practical suggestions?
CONSTRUCT's /only means /no-tricks, for instance.
So does INSERT and APPEND /only, the trick being inlining block values.
But BIND is using /only to mean /shallow right now.
Ladislav
25-Mar-2010
[1790]
one more example in hope, that it will be understandable enough. 
First, the description in words: we define a function obtaining a 
block of code, which uses e.g. a Repeat loop. During the loop, the 
Block argument shall be executed too, but bound to the loop context, 
to be able to use the loop variable (s). The code looks as follows:

a-function: func [block [block!]] [
    repeat i 1 [do-in-context block 'i]
]

do-in-context: func [block [block!] context [word! object!]] [do 
bind block context]


I hope, that everyone understands, that this may well be a part of 
a real-world application, but my example is minimized to contain 
only the constructs that illustrate the problem. Now, in R2 the block 
will be executed "in the right context", being able to use the cycle 
variable 'i. In R3, the block is executed "in the wrong context", 
since the 'self variable will be bound, which was unsolicited.
BrianH
25-Mar-2010
[1791x2]
And "since the 'self variable will be bound, which was unsolicited" 
is the key. Binding the hidden 'self field is the bad thing here.
But that is contextual (in the real sense of the term, not the REBOL 
term). In this case it's the fact that this is a loop function, and 
we don't expect or want 'self to be overriden by a loop function.
Ladislav
25-Mar-2010
[1793]
Generally, I consider 'self binding as unsolicited for purposes like: 
loop constructs, functions, closures, use, etc. For a similar opinion, 
see also CureCode bug #447.
BrianH
25-Mar-2010
[1794]
Agreed :)
Ladislav
25-Mar-2010
[1795]
But, as the above example illustrates, once we have an "obligatory 
self" in every context, unsolicited binding *will happen*
BrianH
25-Mar-2010
[1796]
Nope. As #447 demonstrated, it's optional.
Ladislav
25-Mar-2010
[1797]
That does not mean, that I do not understand the reasons, why BrianH 
proposed the "obligatory 'self" variant, it just means, that I have 
different priorities
BrianH
25-Mar-2010
[1798]
The loop functions just aren't using that option yet. And we can't 
see the option since it's internal.
Ladislav
25-Mar-2010
[1799x2]
#447 does not illustrate that it is optional, it just illustrates, 
that the problem can be circumvented, but only in special cases
as demonstrated above, the general case "cannot be circumvented"
BrianH
25-Mar-2010
[1801x2]
So I propose that the loop functions use that option (#1529). And 
I *separately* propose that the option be made visible to users (#1543).
What we *can't* do is to make the hidden 'self field not there at 
all, since there's no syntax that would support that as an option.
Ladislav
25-Mar-2010
[1803]
By "general case" I mean the case of the Do-in-context function.
BrianH
25-Mar-2010
[1804]
So it's either always there, or never there. It can't be an option 
of object creation - the syntax won't support it. We already went 
through this with case-sensitive maps.
Ladislav
25-Mar-2010
[1805]
(so, we have a situation of conflicting interests here)
BrianH
25-Mar-2010
[1806x3]
However, we *can* make it an option of BIND. It's already a binding 
option for natives, we just can't see it from REBOL code.
It's not a matter of interests. In order to make one object have 
a hidden 'self field, and another not, we need to have more than 
one object type. This isn't a matter of preference, it's inherent 
in the syntax of MAKE.
Now when it comes to our interests, they are aligned. I agree that 
loop functions shouldn't bind 'self (#1529), and that functions should 
allow self in their argument lists (#1528), and that people should 
be able to bind a block without binding 'self if they don't want 
to (#1543). I also agree that /no-self is a dumb name and don't have 
a better one that isn't taken.
Ladislav
25-Mar-2010
[1809]
By "conflict of interests" I mean:


1) the interest to have seamlessly working loops, functions, closures, 
Use, etc. By "seamlessly" I understand "working without ever doing 
unsolicited 'self binding.

2) the interest to have a simple syntax for Mold/Load to describe 
these contexts


As far as I am concerned, 1) is a priority for me, therefore I prefer 
to have a different syntax for this type of contexts. Another possible 
option, which *might* be considered as an alternative is, to have 
a /self refinement for Bind as in BIND/SELF, since that variant covers 
the minority of use cases (just objects and modules), but I doubt 
it cold be called "functionally clean" anyway, thus, probably still 
violating 1)
BrianH
25-Mar-2010
[1810x4]
But we agree on those things.
just objects and modules

 *and scripts* - 'self is bound in script code too. It affects all 
 REBOL code.
And it's not unsolicited there either, it's an intentional feature.
If you want the 'self trick to be an option, you must realize that 
almost all R3 code will be processed *with* that option. LOAD, DO, 
INTERN, MAKE-MODULE, DO-NEEDS and IMPORT will all need to use that 
option, so that means that most code will have 'self bound.
Ladislav
25-Mar-2010
[1814x2]
even adding scripts (I consider the usage of 'self quite rare in 
scripts anyway) we get a minority, since one script typically defines 
many functions/Use/closures/loops, etc.
even adding scripts (I consider the usage of 'self quite rare in 
scripts anyway) we get a minority, since one script typically defines 
many functions/Use/closures/loops, etc.
BrianH
25-Mar-2010
[1816]
It's not so rare anymore in scripts: self is the new system/words.