如何在Lisp中找到一个类的包?

编程入门 行业动态 更新时间:2024-10-07 16:16:28
本文介绍了如何在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添加到阴影在其 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中找到一个类的包?

本文发布于:2023-07-04 09:20:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1022293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中找到   如何在   Lisp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!