Hi all,
I built a system that parses xml files and creates CLOS instances according
to entities parsed. I wonder if there is a method/function which fetches
the slots defined in the class. In practice
(defclass myobj ()
((slot1 ...)
(slot2 ...)
)
(setf foo (make-instance 'myobj
...)
(list-object-slots foo)
> ((slot1 ...)
(slot2 ...))
Thankx
-C.
Rocchi Cesare wrote:
> Hi all,
>
> I built a system that parses xml files and creates CLOS instances according
> to entities parsed. I wonder if there is a method/function which fetches
> the slots defined in the class.
unfortunately there is no standard on that particular aspect of CLOS, so
there is no one answer. which Lisp are you using?
ACL has class-slots, MCL (IIRC) makes you take the union of
class-direct-slots and class-indirect-slots.
suggest you do (apropos 'slots) and look for a likely candidate.
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
the bath water is cold." -- Lorraine Lee Cudmore
Kenny Tilton <·······@nyc.rr.com> writes:
> Rocchi Cesare wrote:
> > Hi all,
> > I built a system that parses xml files and creates CLOS instances
> > according
>
> > to entities parsed. I wonder if there is a method/function which fetches
> > the slots defined in the class.
>
>
> unfortunately there is no standard on that particular aspect of CLOS,
> so there is no one answer. which Lisp are you using?
The AMOP book should serve mostly as pseudo-standard.
> ACL has class-slots, MCL (IIRC) makes you take the union of
> class-direct-slots and class-indirect-slots.
AMOP defines both class-slots and class-direct-slots.
--
Duane Rettig ·····@franz.com Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182
Duane Rettig wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
>
>>unfortunately there is no standard on that particular aspect of CLOS,
>>so there is no one answer. which Lisp are you using?
>
>
> The AMOP book should serve mostly as pseudo-standard.
"should", "mostly" and "pseudo" duly noted. :)
>>ACL has class-slots, MCL (IIRC) makes you take the union of
>>class-direct-slots and class-indirect-slots.
>
>
> AMOP defines both class-slots and class-direct-slots.
>
this doesn't help me answer the OP, esp. if they are using MCL. ACL does
not always follow AMOP either. So for any specific question not covered
by the ANSI spec (I checked! I swear I checked!!!) I am loathe to give
"the answer" when i do not even know which implementation they are using.
--
kenny tilton
clinisys, inc
http://www.tilton-technology.com/
---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
the bath water is cold." -- Lorraine Lee Cudmore
In article <····························@posting.google.com>, Rocchi Cesare wrote:
> I built a system that parses xml files and creates CLOS instances according
> to entities parsed. I wonder if there is a method/function which fetches
> the slots defined in the class. In practice
(defun class-slot-names (c-name)
"Given a CLASS-NAME, returns a list of the slots in the class."
#+(or allegro lispworks scl)
(mapcar #'clos:slot-definition-name
(clos:class-slots (find-class c-name)))
#+sbcl (mapcar #'sb-pcl::slot-definition-name
(sb-pcl:class-slots (sb-pcl:find-class c-name)))
#+cmu (mapcar #'pcl::slot-definition-name
(pcl:class-slots (pcl:find-class c-name)))
#+mcl
(let* ((class (find-class class-name nil)))
(when (typep class 'standard-class)
(map 'list #'car (ccl::%class-instance-slotds class))))
#-(or allegro lispworks cmu mcl sbcl scl)
(error "class-slot-names is not defined on this platform")
)
--
Kevin Rosenberg | .''`. ** Debian GNU/Linux **
http://b9.com/debian.html | : :' : The universal
GPG signed and encrypted | `. `' Operating System
messages accepted. | `- http://www.debian.org/
In article <····················@boa.b9.com>,
Kevin Rosenberg <·····@rosenberg.net> wrote:
> In article <····························@posting.google.com>, Rocchi Cesare
> wrote:
> > I built a system that parses xml files and creates CLOS instances according
> > to entities parsed. I wonder if there is a method/function which fetches
> > the slots defined in the class. In practice
>
> (defun class-slot-names (c-name)
> "Given a CLASS-NAME, returns a list of the slots in the class."
> #+(or allegro lispworks scl)
> (mapcar #'clos:slot-definition-name
> (clos:class-slots (find-class c-name)))
> #+sbcl (mapcar #'sb-pcl::slot-definition-name
> (sb-pcl:class-slots (sb-pcl:find-class c-name)))
> #+cmu (mapcar #'pcl::slot-definition-name
> (pcl:class-slots (pcl:find-class c-name)))
> #+mcl
> (let* ((class (find-class class-name nil)))
> (when (typep class 'standard-class)
> (map 'list #'car (ccl::%class-instance-slotds class))))
> #-(or allegro lispworks cmu mcl sbcl scl)
> (error "class-slot-names is not defined on this platform")
> )
Try this version for MCL. Above does not even try to work
(identifier class-name ???) ...
For (Open)MCL you need to look for instance and for class slots.
(defun class-slot-names (c-name)
"Given a CLASS-NAME, returns a list of the slots in the class."
#+(or allegro lispworks scl)
(mapcar #'clos:slot-definition-name
(clos:class-slots (find-class c-name)))
#+sbcl (mapcar #'sb-pcl::slot-definition-name
(sb-pcl:class-slots (sb-pcl:find-class c-name)))
#+cmu (mapcar #'pcl::slot-definition-name
(pcl:class-slots (pcl:find-class c-name)))
#+mcl
(let* ((class (find-class c-name nil)))
(when (typep class 'standard-class)
(nconc (mapcar #'car (ccl:class-instance-slots class))
(mapcar #'car (ccl:class-class-slots class)))))
#-(or allegro lispworks cmu mcl sbcl scl)
(error "class-slot-names is not defined on this platform"))