Does anyone know what ought to happen in the following situation?
I have accidentally defined THE-SLOT of class BAR without an
initarg :THE-SLOT,
but when i call change-class with :THE-SLOT 0, no error is
triggered,
and THE-SLOT gets initialized to 0.
If i do not add the after method update-instance-for-different-class,
then it does indeed trigger an error in this situation.
(defclass foo () ())
(defclass bar (foo)
((the-shot :initform nil :accessor the-shot)))
(defmethod update-instance-for-different-class :after ((foo foo) (bar
bar) &key &allow-other-keys)
(format t "the-shot=~A~%" (the-shot bar)))
(let ((obj (make-instance 'foo)))
(change-class obj 'bar :the-shot 0)
(the-shot obj))
Here is the SBCL transcript.
CL-USER>
(defclass foo () ())
(defclass bar (foo)
((the-shot :initform nil :accessor the-shot)))
#<STANDARD-CLASS BAR>
CL-USER>
; No value
CL-USER> (let ((obj (make-instance 'foo)))
(change-class obj 'bar :the-shot 0)
(the-shot obj))
; Evaluation aborted
CL-USER> (defmethod update-instance-for-different-class :after ((foo
foo) (bar bar) &key &allow-other-keys)
(format t "the-shot=~A~%" (the-shot bar)))
#<STANDARD-METHOD UPDATE-INSTANCE-FOR-DIFFERENT-CLASS :AFTER (FOO
BAR)
{1000035611}>
CL-USER> (let ((obj (make-instance 'foo)))
(change-class obj 'bar :the-shot 0)
(the-shot obj))
the-shot=NIL
NIL
CL-USER>
From: Ken Tilton
Subject: Re: what should change-class do if invalid initarg is passed?
Date:
Message-ID: <eAoxh.1058$TQ7.40@newsfe12.lga>
cadence wrote:
> Does anyone know what ought to happen in the following situation?
> I have accidentally defined THE-SLOT of class BAR without an
> initarg :THE-SLOT,
> but when i call change-class with :THE-SLOT 0, no error is
> triggered,
> and THE-SLOT gets initialized to 0.
>
> If i do not add the after method update-instance-for-different-class,
> then it does indeed trigger an error in this situation.
>
> (defclass foo () ())
> (defclass bar (foo)
> ((the-shot :initform nil :accessor the-shot)))
>
> (defmethod update-instance-for-different-class :after ((foo foo) (bar
> bar) &key &allow-other-keys)
It is not change-class that is or is not being fussy, it is u-i-f-d-c,
and in this case not because you specified &allow-other-keys.
kenny
> (format t "the-shot=~A~%" (the-shot bar)))
>
> (let ((obj (make-instance 'foo)))
> (change-class obj 'bar :the-shot 0)
> (the-shot obj))
>
> Here is the SBCL transcript.
>
> CL-USER>
> (defclass foo () ())
> (defclass bar (foo)
> ((the-shot :initform nil :accessor the-shot)))
>
> #<STANDARD-CLASS BAR>
> CL-USER>
> ; No value
> CL-USER> (let ((obj (make-instance 'foo)))
> (change-class obj 'bar :the-shot 0)
> (the-shot obj))
> ; Evaluation aborted
> CL-USER> (defmethod update-instance-for-different-class :after ((foo
> foo) (bar bar) &key &allow-other-keys)
> (format t "the-shot=~A~%" (the-shot bar)))
> #<STANDARD-METHOD UPDATE-INSTANCE-FOR-DIFFERENT-CLASS :AFTER (FOO
> BAR)
> {1000035611}>
> CL-USER> (let ((obj (make-instance 'foo)))
> (change-class obj 'bar :the-shot 0)
> (the-shot obj))
> the-shot=NIL
> NIL
> CL-USER>
>
--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd
In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
I did suspect of course it had something to do with either
the @key or @allow-other-keys? If i specify @allow-other-keys
one method does that make it implicit on all methods
of the generic function?
If so, what is a better way for me to declare my after method on
u-i-f-d-c?
-jim
On Feb 4, 6:19 pm, Ken Tilton <·········@gmail.com> wrote:
> cadence wrote:
> > Does anyone know what ought to happen in the following situation?
> > I have accidentally defined THE-SLOT of class BAR without an
> > initarg :THE-SLOT,
> > but when i call change-class with :THE-SLOT 0, no error is
> > triggered,
> > and THE-SLOT gets initialized to 0.
>
> > If i do not add the after method update-instance-for-different-class,
> > then it does indeed trigger an error in this situation.
>
> > (defclass foo () ())
> > (defclass bar (foo)
> > ((the-shot :initform nil :accessor the-shot)))
>
> > (defmethod update-instance-for-different-class :after ((foo foo) (bar
> > bar) &key &allow-other-keys)
>
> It is not change-class that is or is not being fussy, it is u-i-f-d-c,
> and in this case not because you specified &allow-other-keys.
>
> kenny
>
>
>
> > (format t "the-shot=~A~%" (the-shot bar)))
>
> > (let ((obj (make-instance 'foo)))
> > (change-class obj 'bar :the-shot 0)
> > (the-shot obj))
>
> > Here is the SBCL transcript.
>
> > CL-USER>
> > (defclass foo () ())
> > (defclass bar (foo)
> > ((the-shot :initform nil :accessor the-shot)))
>
> > #<STANDARD-CLASS BAR>
> > CL-USER>
> > ; No value
> > CL-USER> (let ((obj (make-instance 'foo)))
> > (change-class obj 'bar :the-shot 0)
> > (the-shot obj))
> > ; Evaluation aborted
> > CL-USER> (defmethod update-instance-for-different-class :after ((foo
> > foo) (bar bar) &key &allow-other-keys)
> > (format t "the-shot=~A~%" (the-shot bar)))
> > #<STANDARD-METHOD UPDATE-INSTANCE-FOR-DIFFERENT-CLASS :AFTER (FOO
> > BAR)
> > {1000035611}>
> > CL-USER> (let ((obj (make-instance 'foo)))
> > (change-class obj 'bar :the-shot 0)
> > (the-shot obj))
> > the-shot=NIL
> > NIL
> > CL-USER>
>
> --
> Well, I've wrestled with reality for 35 years, Doctor, and
> I'm happy to state I finally won out over it.
> -- Elwood P. Dowd
>
> In this world, you must be oh so smart or oh so pleasant.
> -- Elwood's Mom
From: Ken Tilton
Subject: Re: what should change-class do if invalid initarg is passed?
Date:
Message-ID: <i2qxh.1088$lS1.822@newsfe08.lga>
cadence wrote:
> I did suspect of course it had something to do with either
> the @key or @allow-other-keys? If i specify @allow-other-keys
> one method does that make it implicit on all methods
> of the generic function?
Yes. I think. :)
>
> If so, what is a better way for me to declare my after method on
> u-i-f-d-c?
Don't specify &allow-other-keys?
I am not real solid on this. ISTR some issues with ACL (on
initialize-instance never whining about bad initargs) and Franz techies
telling me this or that and me saying this or that and them sending me a
patch but I do not see it now. But this is what you are up against.
Why are you specifying &allow-other-keys, btw?
ken
--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd
In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
From: Pascal Costanza
Subject: Re: what should change-class do if invalid initarg is passed?
Date:
Message-ID: <52mkuqF1ns5jrU1@mid.individual.net>
cadence wrote:
> I did suspect of course it had something to do with either
> the @key or @allow-other-keys? If i specify @allow-other-keys
> one method does that make it implicit on all methods
> of the generic function?
>
> If so, what is a better way for me to declare my after method on
> u-i-f-d-c?
In your case, it should be sufficient to say &key, but omit
&allow-other-keys.
It is &allow-other-keys that declares all initialization arguments as valid.
See Section 7.1.2 in the HyperSpec for a complete specification under
what circumstances an initarg becomes valid.
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/