Does anyone know why CLOS requires that a class
be defined before you can define a method specializing
on it? This restriction seems needless to me. There
is no corresponding restrictions on functions, you
can reference a function before defining it?
Does anyone see any logic behind this restriction?
-jim
Jimka wrote:
> Does anyone know why CLOS requires that a class
> be defined before you can define a method specializing
> on it? This restriction seems needless to me. There
> is no corresponding restrictions on functions, you
> can reference a function before defining it?
>
> Does anyone see any logic behind this restriction?
I can only speculate, but the following reason may be possible:
- The MOP specification wasn't finished yet. They didn't want to make it
too hard to specify the MOP.
- Specifically, there is a need to record the methods with the classes
they are specialized on. The current MOP design for
forward-referenced-class would in principle allow you to do this, but...
- ...probably most importantly, the class a parameter is specialized on
isn't necessarily an instance of standard-class, it could as well be an
instance of structure-class or something else. Switching from
forward-referenced-class to, say, built-in-class would probably be too
complicated.
If you really need this, it should be possible to define your own
defmethod macro that would expand into something like this:
(progn
(unless (find-class 'some-class nil)
(defclass some-class () ()))
(defmethod m ((arg some-class) ...)
...))
Pascal
--
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/