Hi,
Could anyone care to explain following behavior of
ensure-class-using-class?
(without-package-locks
(defmethod mop:ensure-class-using-class :around (class name &rest args)
(declare (ignore args))
(print `(e-c-u-c class ,class name ,name))
(call-next-method)))
(defclass my-meta (standard-class) ())
(defclass my-class ()
()
(:metaclass my-meta))
Entering the above definition in the REPL, I get:
(E-C-U-C CLASS NIL NAME MY-CLASS)
Repeating the definition in the REPL, gives:
(E-C-U-C CLASS #<MY-META MY-CLASS> NAME MY-CLASS)
It seems that method specialized for my-meta would be triggered only
after redefinition of my-class. On definition, the class argument is
nil. My Lisp implementation is Allegro CL. Same thing happens in SBCL,
so I guess it's a design and not a bug in PCL or Allegro's MOP.
Thanks, /S
zaks wrote:
> Hi,
>
> Could anyone care to explain following behavior of
> ensure-class-using-class?
>
> (without-package-locks
> (defmethod mop:ensure-class-using-class :around (class name &rest args)
> (declare (ignore args))
> (print `(e-c-u-c class ,class name ,name))
> (call-next-method)))
>
> (defclass my-meta (standard-class) ())
>
> (defclass my-class ()
> ()
> (:metaclass my-meta))
>
> Entering the above definition in the REPL, I get:
>
> (E-C-U-C CLASS NIL NAME MY-CLASS)
>
> Repeating the definition in the REPL, gives:
>
> (E-C-U-C CLASS #<MY-META MY-CLASS> NAME MY-CLASS)
>
> It seems that method specialized for my-meta would be triggered only
> after redefinition of my-class. On definition, the class argument is
> nil. My Lisp implementation is Allegro CL. Same thing happens in SBCL,
> so I guess it's a design and not a bug in PCL or Allegro's MOP.
Yes, this is actually specified in the CLOS MOP specification - see
http://www.lisp.org/mop/index.html
I think both ensure-class-using-class and
ensure-generic-function-using-class are rather useless because the first
argument is nil when a class / gf is first defined. (The second argument
is a symbol, so you cannot usefully specialize the second argument either.)
However, I haven't seen a case yet which you couldn't handle as well by
specializing initialize-instance / reinitialize-instance (on my-meta in
your case).
Pascal
--
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/