i want to store a "shared" value in my property list as described this
example:
(name "jane doe" age 10 hair-color <shared hc1> ... other attributes)
(name "john doe" age 14 hair-color <shared hc1> ... other attributes)
hc1 is an object with value "brown"
if i change the object hc1 to "blond", both jane and john should now become
blond. i don't want to keep track of all items that are using hc1--lisp
should do that for me.
i'm doing a defstruct to define a "shared-value" object, with hair-color's
value being a shared-value object type. another option is to use a
cons/pair, use car to point to the fact that "this is a shared value", and
cdr to point to the value.
two questions:
1. is there a better or more efficient way of doing this? (is there a "box"
type object, something that signals indirection?)
2. how would i change hc1? if hc1 is a structure or class, i would use its
mutators, but if it's a string or symbol, i may be forced to create a box to
contain the value, so i could change hc1 to "point" to another value.
(either this is the only way to do it, or i'm getting lost in the pointers)
"Masoud Pirnazar" <···········@apptek.com> wrote in message
···············@dispatch.concentric.net...
> i want to store a "shared" value in my property list as described this
> example:
>
> (name "jane doe" age 10 hair-color <shared hc1> ... other attributes)
> (name "john doe" age 14 hair-color <shared hc1> ... other attributes)
>
> hc1 is an object with value "brown"
>
> if i change the object hc1 to "blond", both jane and john should now become
> blond. i don't want to keep track of all items that are using hc1--lisp
> should do that for me.
>
> i'm doing a defstruct to define a "shared-value" object, with hair-color's
> value being a shared-value object type. another option is to use a
> cons/pair, use car to point to the fact that "this is a shared value", and
> cdr to point to the value.
>
>
> two questions:
> 1. is there a better or more efficient way of doing this? (is there a "box"
> type object, something that signals indirection?)
> 2. how would i change hc1? if hc1 is a structure or class, i would use its
> mutators, but if it's a string or symbol, i may be forced to create a box to
> contain the value, so i could change hc1 to "point" to another value.
> (either this is the only way to do it, or i'm getting lost in the pointers)
>
If you use any structure or class and assign it to a variable and then use that
variable in your properties you should get what I think you are asking for...
ie:
CL-USER 20 > (defvar jane nil)
JANE
CL-USER 21 > (defstruct hair color)
HAIR
CL-USER 22 > (defvar *hc1* (make-hair))
*HC1*
CL-USER 23 > (setf (hair-color *hc1*) "blonde")
"blonde"
CL-USER 24 > (setf (get 'hair jane) *hc1*)
#S(HAIR COLOR "blonde")
CL-USER 25 > (get 'hair jane)
#S(HAIR COLOR "blonde")
CL-USER 26 > (setf (hair-color *hc1*) "mauve")
"mauve"
CL-USER 27 > (get 'hair jane)
#S(HAIR COLOR "mauve")
Does that fit the bill?
Coby
--
(remove #\space "coby . beck @ opentechgroup . com")