From: Iban HATCHONDO
Subject: Objects and MOP
Date: 
Message-ID: <3B803617.3188F01A@yahoo.fr>
Greetings,
I need your advise on a "good" way to save information on class
definition.
What I want is a way to get all the initargs of a given class, but I
can't figure how to do that on a portable way with the MOP.

Here is a solution I got , but please let me know what do you think of
it (especially if it exists a better way to get that)


------------------------

(defparameter class-initargs (make-hash-table))

(defun get-class-initargs (class-symbol-name)
  (getf (gethash class-symbol-name class-initargs) :initargs))

(defun get-precedence-class-initargs (classes)
  (apply #'append (mapcar #'get-class-initargs classes)))

(defun get-slots-initargs (prec-classes slots)
  (loop with prec-initargs = (get-precedence-class-initargs
prec-classes)
 for slot in slots
 for initarg = (getf (cdr slot) :initarg)
 when initarg collect initarg into initargs
 finally (return (nconc initargs prec-initargs))))

(defmacro define-class (name (&rest prec-classes) (&rest slots))
  `(progn
     (setf (gethash ',name class-initargs)
    '(:initargs ,(get-slots-initargs prec-classes slots)))
     (defclass ,name ,(if prec-classes prec-classes `())
       ,slots)))