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

[REBOL] Re: Dynamically Modifying objects!

From: joel:neely:fedex at: 22-Feb-2003 11:59

Hi, Ed, Ed Dana wrote:
>... I merely stated that this was my solution to the "problem". > > For all intents and purposes, the object is dynamic. > Maybe not in the truest sense of the word, but certainly enough > to achieve my goals. >
Apparently I didn't understand understand your goals. Sorry.
> This was never my intention. I didn't want attributes shared > between parent and child dynamically... > > I wanted the ability to add and remove attributes from the > currently instantiated object. >
I'm not clear on what you mean by "parent" and "child", but here's what I was trying to address:
>> dee: make object! [firstname: "Tweedle"] >> dum: dee >> dee/firstname: "Twaddle"
== "Twaddle"
>> dum/firstname
== "Twaddle" There's only one object here. There just happen to be multiple words that refer to it. Any changes to the one object are visible via any way we can access it. This is different from
>> dee: make object! [firstname: "Tweedle"] >> dum: dee >> dee: make dee [middlename: "Xavier"] >> dum/middlename
** Script Error: Invalid path value: middlename ** Near: dum/middlename where "the currently instantiated object" isn't changed at all, but a new object is constructed and one of the words is set to refer to that new one. If your goals are such that you always have a single specific word (or some other distinguished reference) that you're using, and never have to e.g. pass as an argument to a function, keep up with via a reference in a block, etc. then by all means, ignore the suggestion for an extra layer. -jn- PS: Another way to use multiple reference capability using your implementation would be simply stick the (replaceable) object into a block, and hand around references to the block, as in:
>> contact: reduce [make malleable! [name: "Fred Flintstone"]]
== [ make object! [ _Add: func [Data [block!]][ Make Self Data ] _Class: 'Malleable ...
>> contact/1/_data
== [name]
>> customer: contact
== [ make object! [ _Add: func [Data [block!]][ Make Self Data ] _Class: 'Malleable ...
>> change contact contact/1/_add [address: "001 Shale Slope"]
== []
>> customer/1/_data
== [name address] Of course, this depends on the convention of unwrapping one layer of reference, so there's not much gain...