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

Re: getting the names of clos object slots

Dan Stanger <dxs@evolving.com> asked:

> 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)
) )

Don Cohen <donc@ISI.EDU> wrote about structures:

> 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.

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

                    Bruno Haible