Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

FAQ: Object-oriented Programming in Lisp 5/7 [Monthly posting]
Section - [5-5] Given the name of a class, how can I get the names of its slots?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Restaurant inspections ]


Top Document: FAQ: Object-oriented Programming in Lisp 5/7 [Monthly posting]
Previous Document: [5-4] How can I store data and CLOS instances (with possibly circular references) on disk so that they may be
Next Document: [5-6] Free CLOS software.
See reader questions & answers on this topic! - Help others by sharing your knowledge

(defun class-slot-names (class-name)
  "Given a CLASS-NAME, returns a list of the slots in the class."
  (mapcar #'clos:slot-definition-name
          (clos:class-slots (find-class class-name))))

(defmethod class-slot-names ((instance standard-object))
  "Given an INSTANCE, returns a list of the slots in the instance's class."
  (mapcar #'clos:slot-definition-name
          (clos:class-slots (class-of instance))))

You can use CLASS-DIRECT-SLOTS instead of CLASS-SLOTS if you don't
want inherited slots. Note that these functions are from the
meta-object protocol specified in the original X3J13 draft spec
(document X3J13/88-003), and may not be supported by all Lisps.

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA