通用Lisp中的跨包defgeneric/defmethod?

通用Lisp中的跨包defgeneric/defmethod?,lisp,common-lisp,clos,Lisp,Common Lisp,Clos,在CLOS包a中定义泛型并在包B中提供泛型方法的正确方法是什么 提前谢谢你 例如: (defpackage :common (:use :cl)) (in-package :common) (defgeneric compare (a b)) (defmethod compare ((a number) (b number)) (cond ((< a b) -1) ((= a b) 0) (T 1))) (defpackage :a (:

在CLOS包a中定义泛型并在包B中提供泛型方法的正确方法是什么

提前谢谢你

例如:

(defpackage :common (:use :cl))  
(in-package :common)  
(defgeneric compare (a b))

(defmethod compare ((a number) (b number))  
  (cond ((< a b) -1)
        ((= a b) 0)
        (T 1)))

(defpackage :a (:use :cl))  
(in-package :a)  

(defclass foo (a b))

(defmethod compare ((x foo) (y foo)) ...)   
; SBCL isn't able to access this method via the common package
(defpackage:common(:use:cl))
(包装内:通用)
(a、b)
(方法比较((a号)(b号))
(条件(
方法和函数不属于包。符号属于包

(defpackage :common (:use :cl))  
(in-package :common)  
(defgeneric compare (a b))

(defmethod compare ((a number) (b number))  
  (cond ((< a b) -1) ((= a b) 0) (T 1)))

(defpackage :a (:use :cl))  
(in-package :a)  

(defclass foo (a b))
如果COMPARE已从package COMMON导出,则可以编写:

(defmethod common:compare ((x foo) (y foo)) ...)   
(defmethod compare ((x foo) (y foo)) ...)   
如果COMPARE已从package COMMON导出,并且package A将“使用”package COMMON,则您可以编写:

(defmethod common:compare ((x foo) (y foo)) ...)   
(defmethod compare ((x foo) (y foo)) ...)   

非常感谢你!正是我所期望的。