测试符号是否是Common Lisp中的defstruct名称

时间:2013-07-19 20:44:23

标签: common-lisp

如果符号是结构的名称,是否有更简单的方法来测试:

(fboundp 'make-symbol)

1 个答案:

答案 0 :(得分:10)

(defun symbol-names-structure-p (symbol)
  (let ((class (find-class symbol nil)))
    (and class (typep class 'structure-class))))

CL-USER 11 > (defstruct foo bar)
FOO

CL-USER 12 > (symbol-names-structure-p 'bar)
NIL

CL-USER 13 > (symbol-names-structure-p 'foo)
T

也:

CL-USER 14 > (ignore-errors (subtypep 'foo 'structure-object))
T
T

CL-USER 15 > (ignore-errors (subtypep 'bar 'structure-object))
NIL
#<CONDITIONS:ILLEGAL-TYPE-SPECIFIER 402001578B>