Consider the follwing:
(defclass bar ()
((a :initarg :a :initform 'a :accessor bar-a)
(b :initarg :b :accessor bar-b)))
(defmethod initialize-instance :after ((b bar)
&rest initargs
&key &allow-other-keys)
(unless (getf initargs :b)
(setf (slot-value b 'b) (slot-value b 'a))))
My intention here was to use one slot value for initializing the other
if the :initarg for the latter wasn't been supplied to
make-instance. Is this above acceptable way for such things or better
one exists ?
--
Vladimir Zolotykh ······@eurocom.od.ua
Not much diff, but FYI there's a language feature telling you if an
initarg was supplied:
(defmethod initialize-instance :after ((self bar)
&rest initargs
&key (b nil b-supplied)
&allow-other-keys)
(declare (ignore b))
(unless b-supplied
(setf (bar-b self) (bar-a self)))) ;; not sure why slot-value was
used
kenny
clinisys
Vladimir Zolotykh wrote:
>
> Consider the follwing:
>
> (defclass bar ()
> ((a :initarg :a :initform 'a :accessor bar-a)
> (b :initarg :b :accessor bar-b)))
>
> (defmethod initialize-instance :after ((b bar)
> &rest initargs
> &key &allow-other-keys)
> (unless (getf initargs :b)
> (setf (slot-value b 'b) (slot-value b 'a))))
>
> My intention here was to use one slot value for initializing the other
> if the :initarg for the latter wasn't been supplied to
> make-instance. Is this above acceptable way for such things or better
> one exists ?
>
> --
> Vladimir Zolotykh ······@eurocom.od.ua
Yes, that way it seems more elegant. Of course no need to use
slots if accessors could.
Kenny Tilton wrote:
>
> Not much diff, but FYI there's a language feature telling you if an
> initarg was supplied:
>
> (defmethod initialize-instance :after ((self bar)
> &rest initargs
> &key (b nil b-supplied)
> &allow-other-keys)
> (declare (ignore b))
> (unless b-supplied
> (setf (bar-b self) (bar-a self)))) ;; not sure why slot-value was
> used
>
> kenny
> clinisys
>
> Vladimir Zolotykh wrote:
> >
> > Consider the follwing:
> >
> > (defclass bar ()
> > ((a :initarg :a :initform 'a :accessor bar-a)
> > (b :initarg :b :accessor bar-b)))
> >
> > (defmethod initialize-instance :after ((b bar)
> > &rest initargs
> > &key &allow-other-keys)
> > (unless (getf initargs :b)
> > (setf (slot-value b 'b) (slot-value b 'a))))
> >
> > My intention here was to use one slot value for initializing the other
> > if the :initarg for the latter wasn't been supplied to
> > make-instance. Is this above acceptable way for such things or better
> > one exists ?
> >
> > --
> > Vladimir Zolotykh ······@eurocom.od.ua
--
Vladimir Zolotykh ······@eurocom.od.ua
May I guess that SHARED-INITIALIZE would give more accurate
handling in all possible cases than INITIALIZE-INSTANCE could do ?
Vladimir Zolotykh wrote:
>
> Consider the follwing:
>
> (defclass bar ()
> ((a :initarg :a :initform 'a :accessor bar-a)
> (b :initarg :b :accessor bar-b)))
>
> (defmethod initialize-instance :after ((b bar)
> &rest initargs
> &key &allow-other-keys)
> (unless (getf initargs :b)
> (setf (slot-value b 'b) (slot-value b 'a))))
>
> My intention here was to use one slot value for initializing the other
> if the :initarg for the latter wasn't been supplied to
> make-instance. Is this above acceptable way for such things or better
> one exists ?
>
> --
> Vladimir Zolotykh ······@eurocom.od.ua
--
Vladimir Zolotykh ······@eurocom.od.ua