假设我想找出在哪个包中定义了一个类,例如比如说(defclass x()())在p1中定义.一种方法是通过(symbol-package'x)获取软件包.此解决方案的问题是x导出到其他包p2中.还有其他建议吗?
Suppose I want to find out in which package a class is defined, e.g. say (defclass x ()()) is defined in p1. One way could be to get the package via (symbol-package 'x). the problem with this solution is that x is exported in a different package p2. Any other suggestions?
推荐答案正如Rainer Joswig所说,类未在包中定义;符号具有包,类的名称是符号.
As Rainer Joswig said, classes aren't defined in packages; symbols have packages and the name of a class is a symbol.
如果您想在读取,编译或加载类定义时了解*PACKAGE*的值(可能是三个不同的值),除非您编写,否则我认为没有任何方法可以检索到该值当时存储它的代码.
If you want to know the value of *PACKAGE* at the time the class definition read, compiled, or loaded (which could conceivably be three different values), I do not believe there is any way to retrieve that unless you write code to store it at that time.
此外,它似乎并不是一条有意义的信息.包只是符号的命名空间,没有理由在读取,编译或加载类定义时使用的包与该类本身无关.
Furthermore, it doesn't seem like a meaningful piece of information to have. A package is simply a namespace for symbols, and there's no reason the package that was current at the time the class definition was read, compiled, or loaded should have anything to do with the class itself.
但是,如果您真正想要的是将类x的名称驻留在程序包p1中,而p2却将其导出,则您可能会对将x添加到阴影在其 defpackage 表格(或之后).
However, if what you really want is for the name of the class x to reside in a package p1, but p2 exports it, you may be interested in adding x to the shadow list of p1 in its defpackage form (or after).
更多推荐
如何在Lisp中找到一个类的包?
发布评论