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

[REBOL] Bug! path! in objects don't behave the same as path! outside object Re:(

From: rebol:techscribe at: 25-Sep-2000 12:10

Hi Andrew, Aha. Got it. What you are observing is not specific to objects. It is the result of how REBOL evaluates words and paths. Let me simplify your example so that we can more easily focus on the essential difference.
>> base: make object! [ p: "'p in 'base." ] >> derived: make object! [ p: 'base/p ]
1. Word evaluation: a) word references a path that evaluates to a string.
>> p: 'base/p
== base/p
>> :p
== base/p
>> p
== "'p in 'base." b) word references a path that evaluates to a path:
>> r: 'derived/p
== derived/p
>> :r
== derived/p
>> r
== base/p In both cases when REBOL evaluates a word and the word evaluates to a path, then REBOL returns the value that is referenced by the path. It stops dereferencing values at the second level as demonstrate by r. The evaluator return base/p and did not continue to dereference the path base/p. Compare to: 2. Path evaluation:
>> derived/p
== base/p Re: 1. (a and b) When REBOL evaluates a word, and the returned value is a path, then REBOL returns the value referred to by that path. Re: 2. When REBOL evaluates a path, then it returns the value that path is associated with. Unlike case 1., the path returned by evaluating the top-level path is not dereferenced. 3. In both cases 1. and 2. if the returned value is a function, then that function is evaluated and the value resulting from evaluating the function is returned. So what you are dealing with here is an exception that REBOL evaluator makes for words, when those words evaluate to paths. You can say that with respect to this behavior the REBOL evaluator works something like this: evaluate: func [something [any-type!]] [ if value? 'something [ either all [ word? get 'something path? get get 'something ] [ return get get 'something ][ return get 'something ] ] return print "unset" ]
>> evaluate p
== "'p in 'base."
>> evaluate derived/p
== base/p Note that this really has nothing to do with objects. You can do the same thing with blocks:
>> block: [ p "'p in 'block" ]
== [p "'p in 'block"]
>> block/p
== "'p in 'block" Word is assigned a path:
>> p: 'block/p
== block/p When the REBOL evaluator discovers that the word p is referencing a path, then the path is dereferenced as well:
>> p
== "'p in 'block" But when REBOL is evaluating a path (this time associated with a block) then unlike when evaluating a word, the evaluation is not repeated for the referenced path:
>> derived: [ p block/p ]
== [p block/p]
>> derived/p
== block/p In short, REBOL is consistent with respect to the distinction it makes between evaluating words and evaluating paths. The way REBOL treats path is not specific to objects. Hope this helps, ;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books http://www.REBOLpress.com visit me at http://www.TechScribe.com