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

[REBOL] Re: Binding

From: lmecir:mbox:vol:cz at: 20-Nov-2002 2:36

Hi Robert,
> in Rebol a block is just a > container. The words inside the block carry the context around.
Well said.
> Can this > context be read, printed? Would it be possible to have named contexts? > This would help a lot IMO.
Of course, you can collect sample words of some contexts and check all words which context they are from. The trouble is, that some context are "being created" during the evaluation of a rebol script, which means, that your collection may never be complete. Example: use [x] ['x] Whenever the USE function is evaluated, it creates a new context, i.e. if you evaluate the above code line three times, you will create three new contexts. Sample context-creating functions: USE, MAKE (OBJECT! FUNCTION!), REPEAT, FOREACH. Any function from the above list creates exactly one context whenever it is evaluated. Illustration: block: [] loop 2 [append block use [x] ['x]] ; == [x x] set block/1 1 set block/2 2 reduce block ; == [1 2]
> I read somewhere in your ... > articles that the context of a word can be changed. Is this right?
1) Yes. That is what e.g. BIND normally does for Rebol blocks. It replaces the words contained in the block by their counterparts bound to the specified context, if possible. 2) No. You cannot change the context of a word without replacing the word. (You may ignore this, if it isn't understandable for you ATM)
> I can use a word > as a named-pointer into this context.
Yes, any word from the specified context will do
> ... 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?
Only the context as whole can be freed. If you have got at least one context word, you are (at least theoretically) able to get all words of the specified context using BIND.
> > 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 > > 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.
It might be a good start to colorize the code from the Computed Binding chapter of Contexts.html, what do you think?
> > Moreover "the actual context" is something, that doesn't > > exist, I am sorry. > > I think I now know why: Because the words carry the context around, ... > you have a set of words with a lot of > different contexts, which are used in the actual block.
That's it. -L