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

[REBOL] Re: Nested objects

From: agem:crosswinds at: 27-Jun-2001 14:53

RE: [REBOL] Nested objects [gavin--mckenzie--sympatico--ca] wrote:
> > Hi, > > I'm not sure how to do this... > > Say, I've got a bunch of nested objects that I setup conveniently using > syntax like: > > obj: make object! [ > foo: 1 > bar: 2 > nested-object: > make object! [ > abc: 3 > xyz: 4 > ] > ] > > Now, I want all of my inner objects to have a property that ties them to > their parent objects. I went looking to see if there was such a built-in > property, but the only automatic property of objects appears to be the word > 'self'. >
if you want this only for new objects, obj-class: [ make object![..] ] new-object: do obj-class sub-class: append copy obj-class[extension] if you want to make object, change vars and make from that with inner objects rebound, forget it..
> So, I know that I can easily enough write a routine that walks my tree of > nested objects and attempts to wire them together, but I was hoping that > there was a way I could get it to happen either: > a) automatically > b) with a little extra work when I define the objects; something like: > > obj: make object! [ > foo: 1 > bar: 2 > nested-object: > make object! [ > parent: obj > abc: 3 > xyz: 4 > ] > ] > > That approach seemed promising, except that it seems that parent doesn't > hold a reference to the same 'obj' object, rather it holds a copy. My > testing shows that if I change obj/foo to another value, that > obj/nested-object/parent/foo hasn't changed value. >
your execution order: 1) obj: something 2) nested-object/parent: obj 3) obj: new object with parent-object.. make object![ set 'obj self .. ] sets 'obj at first