How to find the package of a class in lisp?

ε祈祈猫儿з 提交于 2019-12-11 08:14:34

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/9370719/how-to-find-the-package-of-a-class-in-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!