home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / lisp / mcl / 1196 < prev    next >
Encoding:
Text File  |  1992-08-12  |  2.1 KB  |  70 lines

  1. Path: sparky!uunet!sun-barr!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: Function CCL::STRUCTURE-SLOT-NAMES undefined.
  5. Message-ID: <9208121746.AA04056@cambridge.apple.com>
  6. Date: 12 Aug 92 18:48:37 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 56
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: Bill St. Clair
  11. Original-To: frege@crim.eecs.umich.edu
  12. Original-Cc: info-mcl
  13.  
  14. >When apropos'd STRUCTURE-SLOT-NAMES exists in COMMON-LISP-USER package.
  15. >However, I can't use it in MCL 2.0. How do I access the function?
  16.  
  17. There is no such symbol in MCL 2.0. Did you perhaps inadvertently intern
  18. it yourself by passing it to APROPOS? It is best to always pass strings, not
  19. symbols to APROPOS:
  20.  
  21. Welcome to Macintosh Common Lisp Version 2.0!
  22. ? (apropos "STRUCTURE-SLOT")
  23. INSPECTOR::STRUCTURE-SLOTS, Def: FUNCTION
  24. CCL::STRUCTURE-SLOT-VALUE, Def: FUNCTION
  25. CCL::STRUCTURE-SLOT-INDEX, Def: FUNCTION
  26. ? (apropos "STRUCTURE-SLOT-NAMES")
  27. ? (apropos 'structure-slot-names)
  28. STRUCTURE-SLOT-NAMES
  29. ? (symbol-package 'structure-slot-names)
  30. #<Package "COMMON-LISP-USER">
  31.  
  32. There is no exported way to get the names of the slots of a structure.
  33. You can do by accessing MCL internals, but any code that does that
  34. is likely to break in the future (structure classes do not contain
  35. any slot definition objects in MCL. It would solve your problem if
  36. they did). That said, here is some code that works for me in MCL 2.0:
  37.  
  38. ---------------------------------------------------------------------
  39.  
  40. (in-package :ccl)
  41.  
  42. (export 'structure-slot-names)
  43.  
  44. (eval-when (:compile-toplevel :execute)
  45.  
  46. (defmacro sd-slots (sd) `(%svref ,sd 1))
  47.  
  48. )
  49.  
  50.  
  51. (defun structure-slot-names (structure-type)
  52.   (let ((sd (gethash structure-type %defstructs%))
  53.         res)
  54.     (unless sd
  55.       (error "There is no structure named ~s" structure-type))
  56.     (dolist (slotd (sd-slots sd))
  57.       (let ((slot-name (car slotd)))
  58.         (when (symbolp slot-name)
  59.           (push slot-name res))))
  60.     (nreverse res)))
  61.  
  62. #|
  63. ? (defstruct foo x y z)
  64. FOO
  65. ? (structure-slot-names 'foo)
  66. (X Y Z)
  67. |#
  68.