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

[REBOL] Re: object funnies

From: joel:neely:fedex at: 19-Oct-2001 15:06

Hi, again, Rod and Graham, Rod Gaither wrote:
> Much as I like REBOL I find this departure from > the typical "Scope" behavior of other languages > counter intuitive ... > > >I'm actually left wondering why RT chose to implement it in > >this way. It's not intuitive, and nor is it discussed in > >the online core docs. > >
There are lots of different ways in REBOL to create contexts (and please forgive me if I insult your intelligence... ;-) The thing that REBOL does is let us manipulate context/"scope" relationships in ways that are not as convenient (or in some cases possible) in other languages. Consider this example: factory: make object! [ population: 0 artifact: make object! [ myself: none x: 42 clone-me: func [xx] [ population: population + 1 make myself [x: xx] ] ] artifact/myself: artifact census: func [] [print ["There are" population "artifacts."]] ] ur-artifact: factory/artifact When CLONE-ME inside of ARTIFACT refers to POPULATION it is really intended for it to be a word named POPULATION that belongs to a distinct context (that of FACTORY), not automagically creating a new one within the context of ARTIFACT itself. Thus we can do
>> tom: ur-artifact/clone-me 17 >> dick: tom/clone-me 357 >> harry: dick/clone-me 999 >> factory/census
There are 3 artifacts. Since the definition of an OBJECT! can take place within a variety of other constructs that also create contexts, it would be limiting to have *every* set-word within the object (regardless of nesting) interpreted as pertaining to the object's context. Of course, this throws us back into the Fundamental Equation of Legitimate Empowerment: capability = responsibility otherwise known as TANSTAAFL !-} -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com