在lisp中如何找到一个类的包?
假设我想找出一个类是在哪个包中定义的,例如 (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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Rainer Joswig 所说,类不是在包中定义的;而是在包中定义的。符号有包,类的名称是符号。
如果您想知道读取、编译或加载类定义时
*PACKAGE*
的值(可能是三个不同的值),我不相信有任何方法可以检索除非你当时编写代码来存储它。此外,这似乎并不是一条有意义的信息。包只是符号的命名空间,读取、编译或加载类定义时当前的包没有理由与类本身有任何关系。
但是,如果您真正想要的是类 x 的名称驻留在包 p1 中,但 p2 导出它,您可能有兴趣将 x 添加到 shadow p1 列表位于其 defpackage 表单(或之后)。
As Rainer Joswig said, classes aren't defined in packages; symbols have packages and the name of a class is a symbol.
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.
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).