From: Jimka
Subject: specializing on a class before it is defined
Date: 
Message-ID: <1119091704.168717.172060@g47g2000cwa.googlegroups.com>
I notice in the article
http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/faqs/lang/lisp/part5/faq-doc-8.html
and also in my version of cmucl that it is not allowed
to define a method specializing on a class that does not yet exist.
However, I seem to recall reading in AMOP that this should
be allowed.  Is my memory wrong?  Or was this feature considered
and latter decided was not worth supporting.

Is there something conceptually wrong with the idea?  It seems to
me that the classes need not be defined until the generic function
is called.

On the other hand, since classes are very easy to redefine,
one could write a macro around defmethod that would check
for the existance of the classes, define meaningless classes
as necessary, then define the method then define the method.
Then later when the actual class is defined everything should
work correctly.


(def-forward-reference-method mymeth ((f foo) (b bar))
   expr expr expr)

should expand to the following

(progn
  (unless (find-class 'foo)
     (defclass foo nil nil))
  (unless (find-class 'bar)
     (defclass bar nil nil))
  (defmethod mymeth ((f foo) (b bar))
    expr expr expr))