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

[REBOL] Re: Embedded objects - deviation

From: lmecir:mbox:vol:cz at: 13-Mar-2003 9:52

Hi, ----- Original Message ----- From: "James Marsden"
> This bought to mind another possible scenario: > > If Bob has a dog called Rex who has a catfriend called Suzy, can the dog > be made to belong to Bob and the cat linked not belonging (the cat may > have other friends) to BobsDog? > > Preferrably in a short elegant sort of way ;) > > Bob: make object! [name: "Bob"] > BobsDog: make object! [name: "Rex"] > SuzyCat: make object! [name: "Suzy"] > > I envisaged the object to be able to reference suzy as: > SuzyCat/name > Or Bob/BobsDog/SuzyCat/name > > A one liner such as Sunanda's bob & dog example would be nice if > possible - also the ability to go n levels deep with the object > inclusions.
if you insist, you can have a (slightly more complicated) dynamic object dynamic: function [ {make a dynamic object} spec [block!] /inherit object [object!] ] [result] [ result: make object! [data: none] result/data: make either inherit [object/data] [object!] spec result ] add-data: func [ {add data to a dynamic object} dynamic [object!] spec [block!] ] [ dynamic/data: make dynamic/data spec dynamic ] ; tests Bob: dynamic [name: "Bob"] BobsDog: dynamic [name: "Rex"] SuzyCat: dynamic [name: "Suzy"] Bob/data/name ; == "Bob" BobsDog/data/name ; == "Rex" SuzyCat/data/name ; == "Suzy" add-data Bob [BobsDog: rebol/words/BobsDog] Bob/data/BobsDog/data/name ; == "Rex" add-data BobsDog [SuzyCat: rebol/words/SuzyCat] BobsDog/data/SuzyCat/data/name ; == "Suzy" Bob/data/BobsDog/data/SuzyCat/data/name ; == "Suzy" Regards -L