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

[REBOL] Re: Newbie query on array indexing

From: brett:codeconscious at: 23-Nov-2001 22:14

> I can tell you _what_ got set, but the _why_ is beyond me ...
> >> one > == two > >>
Hello, my turn :) a: context [b: 'one] Here an object is created with a single instance variable "b" whose value is literal word "one". This object becomes the value of the word "a". b: 'b Then a new word "b" is given a value. The value of this new word is the literal word "b". set a/:b 'two Now Ammon is getting tricky. Let's break it down. Firstly it is pretty obvious we are setting a word to a value, this value being the literal word two . Volker has shown that the word that is being set is the word "one". So the mystery comes down to the evaluation of the path. Here are two quotes from the Core user guide: <quote> Paths are a collection of words and values delineated with forward slashes (/). Paths are used to navigate to or find something. The words and values of a path are called refinements, and they are combined to provide a means of navigating through a value or function." </quote> <quote> The words supplied as paths are symbolic and therefore unevaluated. This is necessary to allow the most intuitive form for object referencing. To use a word's reference, an explicit word value reference is required: city: 'Ukiah probe USA/CA/:city </quote> BTW, The word "reference" is used twice in that last sentence in two different ways. First to refer to the value of a word, second to talk about the Rebol expression (using a get-word syntax) that will retrieve the word's value. So back to the path Ammon has created Here it again: a/:b Imagine how this path is evaluated. First "a" is encountered it evaluates to an object. Then the next element of the path is evaluated. This is the ":b". Guess what :b will evaluate to.
>> :b
== b So it evaluates to the word "b". But the evalution of the path is not finished. This word b is used now as the selector (of an instance variable) into the object that was returned from the first element in the path. Thus the evalution now is equivalent too:
>> a/b
== one So the path evaluation is complete and has resulted in a value of the word one . This value now becomes a parameter to the set function and so now we have something equivalent to: set 'one 'two HTH Brett.