如何在Lisp中找到一个类的包? [英] How to find the package of a class in lisp?

查看:84
本文介绍了如何在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?

推荐答案

正如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添加到

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中找到一个类的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆