home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!bill@cambridge.apple.com
- From: bill@cambridge.apple.com (Bill St. Clair)
- Newsgroups: comp.lang.lisp.mcl
- Subject: Re: Function CCL::STRUCTURE-SLOT-NAMES undefined.
- Message-ID: <9208121746.AA04056@cambridge.apple.com>
- Date: 12 Aug 92 18:48:37 GMT
- Sender: info-mcl-request@cambridge.apple.com
- Lines: 56
- Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
- Full-Name: Bill St. Clair
- Original-To: frege@crim.eecs.umich.edu
- Original-Cc: info-mcl
-
- >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)
- ?
- |#
-