I'm using PCL with CMU CL, and I get annoying warnings every time I
compile something using generic functions. Here is an example:
(defpackage "CLOS-TEST"
(:use "COMMON-LISP" "PCL")
(:shadowing-import-from "PCL" "CLASS-OF" "CLASS-NAME" "BUILT-IN-CLASS"
"FIND-CLASS"))
(in-package "CLOS-TEST")
(defclass food)
(defclass apple (food))
(defgeneric eat ((what food))
)
(defmethod eat ((what apple))
(format t "MMMMm.."))
(defun doit ()
(eat (make-instance 'apple)))
(The shadowing-import stuff seems to be necessary in CMU CL). When I
compile this I will get warnings that eat is undefined. If I compile
it after having loaded it once, than I don't get the warnings.
I can get rid of the warnings by wrapping both the class definitions
and the defgeneric/defmethod in an eval-when, but that seems a bit
ugly to me. Questions:
* Is it really necessary to wrap all the CLOS stuff in an eval-when?
* Is this specific to using PCL, or is this true of CLOS in general?
* Is this the recommended way of using CLOS with PCL?
All help is appreciated.
Johan Parin
Ericsson AXE Research & Development
In article <··············@uab.ericsson.se>, Johan Parin
<······@uab.ericsson.se> wrote:
> I'm using PCL with CMU CL, and I get annoying warnings every time I
> compile something using generic functions. Here is an example:
Your code has some serious errors/problems:
; If your Common Lisp implementation still needs you
; to import the package PCL, you are
; either making a mistake or get a better Lisp
; implementation.
; If this is a PCL+CMUCL bug,
; see http://www.cons.org/ for informations how
; to report the problem.
(defpackage "CLOS-TEST"
(:use "COMMON-LISP"))
(in-package "CLOS-TEST")
; Defclass takes three require arguments:
; - the class name
; - a (possibly empty) list of superclasses
; - a (possibly empty) list of slot specifications
; You have to provide those.
(defclass food () ())
(defclass apple (food) ())
; You can't specify classes for the arguments
; in DEFGENERIC.
(defgeneric eat (what))
(defmethod eat ((what apple))
(format t "MMMMm.."))
(defun doit ()
(eat (make-instance 'apple)))
Compiling the above with Macintosh Common Lisp works fine.
> * Is it really necessary to wrap all the CLOS stuff in an eval-when?
No.
Remember, you can use a Common Lisp implementation purely
with a batch compilation approach (start a fresh Lisp,
and compile everything with compile-file).
It is for development easier to develop using the usual interactive
(****not**** interpreted, Lisp system still do compile)
approach. You can debug your software much faster.
Possible compilation problems (due to missing functions used
in macro expansions for example) can be fixed later (you should
fix them though - ideally you should be able to compile a file
without loading it before - but it is not strictly necessary).
Interactive development would enable you finding/fixing the
above basic errors easily.
Greetings,
Rainer Joswig
--
http://www.lavielle.com/~joswig/