Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Binding

From: robert:muench:robertmuench at: 19-Nov-2002 23:02

> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]] > On Behalf Of Ladislav Mecir > Sent: Tuesday, November 19, 2002 6:36 PM > To: [rebol-list--rebol--com] > Subject: [REBOL] Re: Binding > Look out! A sentence like this can have no sense at all! Look > at the following example, try it at the console: > > sample-block: [x] > append sample-block use [x] ['x] > sample-block ; == [x x] > > Now we see, that SAMPLE-BLOCK contains two words. Can we say > "SAMPLE-BLOCK is bound to the global context"? No way!
Hi, of course you are right. As said I'm implicitly using all this quite in the right way but there are still some black wholes in my mind about it all and I now decided to fix this ;-). And again, I have programmed to much in C++ etc. so it's really not quite obvious. And (finally) I don't like to much implicit stuff I need to know... It makes life hard.
> Let's make sure: > > x: 1 > get sample-block/1 ; == 1
Ok, that's clear.
> , if we try the same for the second word, we obtain: > > get sample-block/2 > ** Script Error: x has no value > ** Near: get sample-block/2
Because this x is atifically defined to the local block by use [x]['x], right?
> So, can we say, that SAMPLE-BLOCK isn't bound to the global > context? This looks wrong, again, because the first word > clearly *is bound to the global context*.
My mistake was to think of the block as the instance that defines the context (like a namespace in C++) but in Rebol a block is just a container. The words inside the block carry the context around. Can this context be read, printed? Would it be possible to have named contexts? This would help a lot IMO.
> What always makes sense is a question: "To which context is > bound the first word of the SAMPLE-BLOCK?", or "To which > context is bound the second word of the SAMPLE-BLOCK?",
Right. I will print this and tag it to my monitor ;-))
> because words always have a context attribute, i.e. an > information, to which context they are bound.
And that's the big difference! So I read somewhere in your (very good) articles that the context of a word can be changed. Is this right? This would mean that as long as I can get the right context I can use a word as a named-pointer into this context.
> Nevertheless, your question is potentially dangerous, because > you didn't *exactly* specify the words you meant. If you meant
something
> like: > > "Is the word 'object that can be found at: > > foreach [id object] list [ > > (the second element of the block following the word 'foreach) > bound to the global context?", it makes more sense, but the > question is still ambiguous.
I see and I understand it step by step...
> This is something I should explain a bit. Let's have a look > at the SAMPLE-BLOCK as created above. It contains two words, > which are bound to different contexts, although the words > "look the same": > > same? sample-block/1 sample-block/2 ; == false > > It is pretty easy to replace the second word as follows: > > sample-block/2: sample-block/1 > > What is the result of this operation? Both words in the > SAMPLE-BLOCK now have the same binding, they are bound to the > same context!
Ok.
> This means, that I changed the SAMPLE-BLOCK > substantially, although I didn't try to change the binding of > the second word, because I simply replaced it.
And this means that the old word was "overwritten" with a new word that has a different context. The old word is now nowhere referenced and therefore can be freed? Or is Rebol still carrying it around as a word-zombie that can't be accessed anymore?
> I may say, that I changed SAMPLE-BLOCK, by replacing its > second word. This means, that Rebol blocks are dynamic, you > can change them, and you often do, while Rebol words are > being replaced. > I can offer you only the following means to visualize > context: UNBOUND?, GLOBAL?, LOCAL?, EQUAL-BINDING?, > IN-OBJECT?, which can tell you something about words you are > checking. These functions are available in my Contexts.html > article at www.rebolforces.com/~ladislav
Thanks, I already looked at them and try to understand evey line. I'm going to play around with it.
> The trouble with the visualization is, that you can always > compare the binding attributes of two words, but Rebol > doesn't offer us any direct way how to visualize/get the > binding of a word.
But we can collect the number of contexts, right? Further we just can enumerate the contexts and collect all words. From this a graphical representation should be possible. I would love to have a browser for my script that shows me all words, which contexts I have etc. Would be very handy for debugging.
> Moreover "the actual context" is something, that doesn't > exist, I am sorry. A proof:
I think I now know why: Because the words carry the context around, you don't have a single place where you enter a specific context and leave it (namespeace analogy). Instead you have a set of words with a lot of different contexts, which are used in the actual block.
> Let's create SAMPLE-BLOCK again as before, try to execute it > and see, what is going to be the "actual context": > > sample-block: [x] > append sample-block use [x] ['x] > sample-block ; == [x x] > do sample-block > > ** Script Error: x has no value > ** Near: x > > As we made sure, it wasn't be the Global Context, because the > second 'x in SAMPLE-BLOCK isn't global, OTOH, it couldn't > have been any other context, because the first 'x is global. > The only thing we may say is, that the SAMPLE-BLOCK contains > equal words with different binding, IOW, the SAMPLE-BLOCK may > be considered a "mixed context" block.
That's a good description. IMO mixed context block describes the situation very specific.
> Correct answer is: "Before it starts to evaluate the body for > the first time."
;-)) Ok. I know I need to be as specific as it's necessary.
> I could have written analogical simulation of FOREACH as I > wrote for USE, but I guess, that you could write it too now.
Thanks a lot for your time and this great WORD training. I'm sure I will have further questions ;-)). Robert