[REBOL] Re: Embedded objects.
From: joel:neely:fedex at: 12-Mar-2003 20:42
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
> 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! [
and then later have
SomeDog: make object! [
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" [
If we want to allow Bob to possess more than one dog, then
foreach [kind what] Bob/possessions [
if kind = "dog" [append dognames what/name]
Of course, all of the above could be handled more tidily by
defining the appropriate methods on Bob which manage his
Polonius: ... What do you read, my lord?
Hamlet: Words, words, words.
_Hamlet_, Act II, Scene 2