Subject: getting the names of clos object slots

From: [email-masked] (Dan Stanger)
Date: Fri, 20 Jan 1995 15:50:08 -0700

is there a way of getting the names of the slots in a clos object?
thanks,
dan stanger

---

From: [email-masked] (Don Cohen)
Date: Fri, 20 Jan 95 15:26:50 -0800

is there a way of getting the names of the slots in a clos object?
No advertised way, but look at the plist of the symbol that names the
defstruct.
While we're at it, there's genuinely NO way to figure out from the
structure name and the slot name what the accessor is.  
Here is my local fix to a similar problem:
 (progn
  (unless (fboundp 'old-ds-make-accessors)
	  (setf (symbol-function 'old-ds-make-accessors)
		(symbol-function 'system::ds-make-accessors)))
  (lisp:defun new-ds-make-accessors (name type concname slotlist)
    (cons `(setf (get ',name 'concname) ',concname)
	  (old-ds-make-accessors name type concname slotlist)))
  (setf (symbol-function 'system::ds-make-accessors)
	(symbol-function 'new-ds-make-accessors))
  (lisp:defun defstruct-access-function-name (structname slotname)
      (intern (concatenate 'string (get structname 'concname)
			   (symbol-name slotname))
	      (symbol-package structname))))

---

From: [email-masked]
Date: Fri, 20 Jan 1995 18:32:46 -0500

q

---

From: haible (Bruno Haible)
Date: Mon, 23 Jan 95 16:26:39 +0100

> is there a way of getting the names of the slots in a clos object?

How to do this, has not been standardized, so it is implementation dependent.
In CLISP, you can iterate through the (clos::class-slot-location-table class)
hash table. The hash keys are the slot names. Something like this:

(defun class-slots (class)
  (let ((l '()))
    (maphash #'(lambda (slot ignore) (declare (ignore ignore)) (push slot l))
             (clos::class-slot-location-table class)
    )
    l
) )

> structure name and the slot name what the accessor is.

You don't need the accessor once you can use (SLOT-VALUE structure slot-name).

                    Bruno Haible
                    [email-masked]