From: Sam S. <sd...@gn...> - 2005-01-25 23:39:58
|
> * Bruno Haible <oe...@py...t> [2005-01-25 20:24:47 +0100]: > >> (let ((c (find-class name))) >> (if c >> (class-direct-slots c) >> (structure-direct-slots name))) > > This is a hypothetical use case. Doesn't occur in practice. (Where > would the 'name' come from?) I save my objects in text files, writing type and slot names and values. Sometimes I use DEFCLASS and sometimes DEFSTRUCT. I don't want to have to regenerate all my data if I decide to convert my structs to classes. >> (let ((c (class-of object))) >> (if (class-p c) >> (class-direct-slots c) >> (structure-direct-slots (class-name c)))) > > Yes. The second branch can never be taken. For a good reason: There's > no way to use the structure-* API when all you have is an object. If > an object is given and it might be a list or a vector, you cannot > determine which structure it comes from. (Is #(FOO 3 BAR #\X BAZ) a > FOO, a BAR, or a BAZ?) Therefore when all you have is an object, you > can only rely on the class-* API. will this work: (defstruct foo a b c) (class-direct-slots (find-class 'foo)) -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.honestreporting.com> Your mouse pad is incompatible with MS Windows - your HD will be reformatted. |