如何在Common lisp中访问Defclass插槽的:文档字符串

如何在Common lisp中访问Defclass插槽的:文档字符串,class,documentation,common-lisp,Class,Documentation,Common Lisp,好的,下面是我如何实例化我的Defclass和相关的Defmethod和Defparameter (defvar *account-numbers* 0) (defclass bank-account () ((customer-name :initarg :customer-name :initform (error "Must supply a customer name.") :accessor customer-name :documentation "Customer's

好的,下面是我如何实例化我的Defclass和相关的Defmethod和Defparameter

(defvar *account-numbers* 0)

 (defclass bank-account ()
 ((customer-name
 :initarg :customer-name
 :initform (error "Must supply a customer name.")
 :accessor customer-name
 :documentation "Customer's name")
 (balance
 :initarg :balance
 :initform 0
 :reader balance
 :documentation "Current account balance")
  (account-number
   :initform (incf *account-numbers*)
   :reader account-number
   :documentation "Account number, unique within a bank.")
  (account-type
   :reader account-type
   :documentation "Type of account, one of :gold, :silver, or :bronze.")))

(defmethod initialize-instance :after ((account bank-account)
                   &key opening-bonus-percentage)
(when opening-bonus-percentage
  (incf (slot-value account 'balance)
  (* (slot-value account 'balance) (/ opening-bonus-percentage 100)))))

(defparameter *account* (make-instance
         'bank-account
         :customer-name "Ed Monney"
         :balance 1000000000
         :opening-bonus-percentage 5))
我正在尝试访问:文档槽的任何所说的槽值,但一直无法在我正在阅读的书或谷歌中找到信息

我的尝试包括

 (documentation *account* 'balance)
得到了这个错误

警告: 不支持的文档:类型为BANK-ACCOUNT的对象的类型余额

我试过了

(slot-value bank-account ('balance :documentation))
我得到

The variable BANK-ACCOUNT is unbound.
[Condition of type UNBOUND-VARIABLE]
我尝试了我所能想到的所有其他变体
slot value“balance:documentation”文档银行帐户和*account*
我能想到的但只是得到了很多不同的错误学习如何访问defclass slot的:文档有什么帮助吗 非常感谢

编辑:
@雷纳·乔斯维格(Rainer Joswig),这似乎只在我进入repl的defclass之后才起作用……我希望有一种方法,如果我在库中设置了一个defclass或其他东西,我就可以运行一个命令并访问文档。如果我在def类之后在repl中运行其他东西,它们会像你那样发布……当我运行这4行代码时,我会出现一个错误……我尝试了(文档(slot value account'balance)t)在我运行了我的initialize实例和我的defparam帐户(如我的帖子中所述)之后,但出现了错误……您能否建议一种方法使文档更易于访问。

这在通用Lisp标准中没有定义。不幸的是,这也不是初学者的领域

实现可以提供一种访问插槽的文档字符串的方法

LispWorks示例

CL-USER 23 > (defclass foo ()
               ((bar :documentation "this is slot bar in class foo")))
#<STANDARD-CLASS FOO 40200032C3>

CL-USER 24 > (class-slots *)
(#<STANDARD-EFFECTIVE-SLOT-DEFINITION BAR 4020004803>)

CL-USER 25 > (first *)
#<STANDARD-EFFECTIVE-SLOT-DEFINITION BAR 4020004803>

CL-USER 26 > (documentation * 'slot-definition)
"this is slot bar in class foo"
CL-USER 23>(定义类foo()
((条形图:文档“这是foo类中的槽条形图”))
#
CL-USER 24>(类槽*)
(#)
CL-USER 25>(第一个*)
#
CL-USER 26>(文档*插槽定义)
“这是foo类中的老虎机栏”
它也适用于Clozure CL

对于SBCL,其工作原理略有不同

* (defclass foo ()
     ((bar :documentation "this is slot bar in class foo")))

#<STANDARD-CLASS FOO>


* (sb-mop:finalize-inheritance *)

NIL


* (sb-mop::class-slots **)

(#<SB-MOP:STANDARD-EFFECTIVE-SLOT-DEFINITION BAR>)


* (first *)

#<SB-MOP:STANDARD-EFFECTIVE-SLOT-DEFINITION BAR>


* (documentation * t)

"this is slot bar in class foo"
*(定义类foo()
((条形图:文档“这是foo类中的槽条形图”))
#
*(sb mop:完成继承*)
无
*(sb mop::类槽**)
(#)
*(第一*)
#
*(文件*t)
“这是foo类中的老虎机栏”

很抱歉,我忘了提到我确实使用SBCL……您能告诉我如何检索文档吗。字符串在该实现中…感谢您的回复顺便说一句…我非常感谢您查看最新的编辑…感谢您对这个问题的关注=)
*
在回复时,返回上一个评估表单返回的值(
***
倒数第二个,以此类推)。我不知道这是标准的还是具体的,但因为Rainer没有提到任何东西,它可能是标准的:)这应该告诉您如何使用Rainer的示例代码。