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 13:30

Hi Robert,
> > Of course, you can collect sample words of some contexts and > > check all words which context they are from. > > Yes, but I need to know about the context ;-)
It will work, if you try, just use words to "represent" 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. > > Is there a list of all functions that create contexts? IMO this would > help a lot to understand all this.
I would say, that the list is almost complete. Any other function is a derivative of a function from the above list, I think.
> > 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. > > In this case I would say it a bit different: BIND uses the given word as > a human-readable-descriptor. The word has no meaning at all, it's just a > description for BIND that specifies what to search in the context where > the KNOWN-WORD is included and than replaces the descriptor with a word > that has the same descriptor (IIRC you call it the argument of a word) > as the specified one, the same context as KNOWN-WORD and things like the > value of the word etc. are than accessable.
We must take into account the fact, that BIND can either replace a word (if there is a corresponding word in the target context), or leave it untouched (if a corresponding word in the target context doesn't exist). In the latter case the word cannot be just a "human readable descriptor".
> > 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 think I understand this now. The key-word here is REPLACE, the word > looks like the same but it's not. So can we say what is normaly known as > a variable and that is referenced by name in Rebol a variable has two > properties: A name and a context. Only this combination is a full > qualifier for a "variable".
Sounds good.
> > Only the context as whole can be freed. > > Hmm... Isn't this now a bit different in semantics to what we said > before? We are talking about blocks as mixed-context-containers. Ok. We > have contexts as a collection ("block") of words that share the property > same-context but don't have any functional meaning (a context is just a > collection and not a sequence that can be evaluated). So blocks and > contexts are orthogonal. > > So why can't a word be removed from a context? Imagine a context with > 1000 words and only 1 is still in use. Than i have 999 words that are in > memory but not used. Does this explain the memory footprint of Rebol?
Well, see this: w: use [x y] ['x] Do you think, that 'y got lost, because we didn't retain it? But it is still accessible, as long as 'x is accessible, because if we can access one context word, we are able to access them all: block: reduce ['y bind 'y w] ; == [y y] set block [1 2] reduce block
> > 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. > > But we can't query the context, right? I can't say something like: > > foreach word get-context KNOWN-WORD [?? word]
Actually, we can, although there are some exceptions. See this: do http://www.rebolforces.com/~ladislav/contexts.r context-words: function [known-word [word!]] [result] [ result: make block! 0 if unbound? known-word [return first system/words] foreach word first system/words [ if not same? word bind word known-word [ append result word ] ] result ] Now we can: foreach word context-words known-word [?? word] -L