Check if character is defstruct in Common Lisp

Is there an easier way to test if a character is a structure name than this:

(fboundp 'make-symbol) 
+4
source share
1 answer
 (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 

and

 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> 
+10
source

Source: https://habr.com/ru/post/1492389/


All Articles