[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function CCL::STRUCTURE-SLOT-NAMES undefined.



>When apropos'd STRUCTURE-SLOT-NAMES exists in COMMON-LISP-USER package.
>However, I can't use it in MCL 2.0. How do I access the function?

There is no such symbol in MCL 2.0. Did you perhaps inadvertently intern
it yourself by passing it to APROPOS? It is best to always pass strings, not
symbols to APROPOS:

Welcome to Macintosh Common Lisp Version 2.0!
? (apropos "STRUCTURE-SLOT")
INSPECTOR::STRUCTURE-SLOTS, Def: FUNCTION
CCL::STRUCTURE-SLOT-VALUE, Def: FUNCTION
CCL::STRUCTURE-SLOT-INDEX, Def: FUNCTION
? (apropos "STRUCTURE-SLOT-NAMES")
? (apropos 'structure-slot-names)
STRUCTURE-SLOT-NAMES
? (symbol-package 'structure-slot-names)
#<Package "COMMON-LISP-USER">
? 

There is no exported way to get the names of the slots of a structure.
You can do by accessing MCL internals, but any code that does that
is likely to break in the future (structure classes do not contain
any slot definition objects in MCL. It would solve your problem if
they did). That said, here is some code that works for me in MCL 2.0:

---------------------------------------------------------------------

(in-package :ccl)

(export 'structure-slot-names)

(eval-when (:compile-toplevel :execute)

(defmacro sd-slots (sd) `(%svref ,sd 1))

)


(defun structure-slot-names (structure-type)
  (let ((sd (gethash structure-type %defstructs%))
        res)
    (unless sd
      (error "There is no structure named ~s" structure-type))
    (dolist (slotd (sd-slots sd))
      (let ((slot-name (car slotd)))
        (when (symbolp slot-name)
          (push slot-name res))))
    (nreverse res)))

#|
? (defstruct foo x y z)
FOO
? (structure-slot-names 'foo)
(X Y Z)
? 
|#