Class 有没有办法获得班级的名额?

Class 有没有办法获得班级的名额?,class,common-lisp,slots,clos,lispworks,Class,Common Lisp,Slots,Clos,Lispworks,我有一门像这样的课 (defclass shape () ((color :initform :black) (thickness :initform 1) (filledp :initform nil) (window :initform nil))) 如果我只知道这个类的实例,common lisp中是否有函数如何获取这些插槽的列表?许多常见的lisp实现都支持CLOS元对象协议。这为类、插槽和其他元对象提供了内省操作 在LispWorks中,相应的函数可以在包CL-USER中直接

我有一门像这样的课

(defclass shape ()
 ((color :initform :black)
 (thickness :initform 1)
 (filledp :initform nil)
 (window :initform nil)))

如果我只知道这个类的实例,common lisp中是否有函数如何获取这些插槽的列表?

许多常见的lisp实现都支持CLOS元对象协议。这为类、插槽和其他元对象提供了内省操作

在LispWorks中,相应的函数可以在包
CL-USER
中直接访问

CL-USER 139 > (defclass shape ()
                ((color :initform :black)
                 (thickness :initform 1)
                 (filledp :initform nil)
                 (window :initform nil)))
#<STANDARD-CLASS SHAPE 40202910E3>

CL-USER 140 > (mapcar #'slot-definition-name
                      (class-direct-slots (class-of (make-instance 'shape))))
(COLOR THICKNESS FILLEDP WINDOW)
CL-USER 139>(定义类形状()
((颜色:初始形式:黑色)
(厚度:表1)
(filledp:initform nil)
(窗口:initform nil)))
#
CL-USER 140>(地图车#“插槽定义”名称
(类直接插槽(类(生成实例形状)))
(颜色厚度填充P窗口)
函数
slot definition name
class direct slot
由CLO的元对象协议定义,并且在许多常见的Lisp实现中受支持-只是它们所在的包可能不同。例如,在SBCL中,可以在包
SB-MOP
中找到它们

从一个类中,我们可以得到直接插槽的列表。直接插槽是直接为该类定义的且未继承的插槽。如果要获取所有插槽的列表,请使用函数
class slots


Slot在这里意味着我们得到一个Slot定义对象,它描述了Slot。要获取插槽的名称,您必须使用函数
插槽定义名称

从插槽定义对象检索名称:好的,谢谢您的回答。但我还有一个问题。我需要知道课堂上的每一种方法。甚至是继承类中的方法<代码>(defclass point(shape)((x:initform 0)(y:initform 0))有没有办法,如何获得它?请参阅链接的问题。但我不能使用任何外部库。@Micky也请参阅。您还可以使用
(apropos'slot definition name)
找出在您的实现中在哪些包中定义了这些函数。@coredump谢谢,这帮助我了解了如何在sbcl上运行此功能:(mapcar 35;'sb-mop:slot definition name(sb-mop:class direct slot(class of(make instance'shape)))