From: Vladimir Zolotykh
Subject: :initform and slot-value
Date: 
Message-ID: <3C3B14D8.E24CD56E@eurocom.od.ua>
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

From: Kenny Tilton
Subject: Re: :initform and slot-value
Date: 
Message-ID: <3C3B21ED.EC12BE83@nyc.rr.com>
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
From: Vladimir Zolotykh
Subject: Re: :initform and slot-value
Date: 
Message-ID: <3C3B267D.AEFC1FAD@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
From: Vladimir Zolotykh
Subject: Re: :initform and slot-value
Date: 
Message-ID: <3C3C13B6.3FB3C9DE@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