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

[REBOL] Re: Embedded objects.

From: joel:neely:fedex at: 12-Mar-2003 20:42

Hi, Terry, Another approach... Terry Brownell wrote:
> But what if I already have an object "Dog" and simply want to > include that in the Bob object? > > I don't know if Bob will ever have a dog (or an infinite amount > of other things), which prevents me from "pre-loading" the 'pets > block. > > Basically, I want Bob to now "possess" an object called dog ... >
If you want to be able to add arbitrary possessions an unspecified future times, without explicitly planning ahead, then you could do something like this: Bob: make object! [ name: "Bob" posessions: [] ] and then later have SomeDog: make object! [ name: "Rover" ] and let Bob acquire that possession by saying append Bob/possessions reduce ["dog" SomeDog] then, to find out the name of Bob's dog either found? mutt: select Bob/possessions "dog" [ mutt/name ][ "no dog!" ] If we want to allow Bob to possess more than one dog, then dognames: [] foreach [kind what] Bob/possessions [ if kind = "dog" [append dognames what/name] ] print dognames Of course, all of the above could be handled more tidily by defining the appropriate methods on Bob which manage his possessions. -jn- -- Polonius: ... What do you read, my lord? Hamlet: Words, words, words. _Hamlet_, Act II, Scene 2