From: Bruno H. <br...@cl...> - 2005-01-25 19:30:51
|
Sam wrote: > > The user calls either > > (class-direct-slots (find-class name)) > > or > > (structure-direct-slots name) > > > > depending on what he wants. > > what if he does not know whether NAME is implemented with a DEFCLASS or > a DEFSTRUCT? > you want him to write > > (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?) > or > > (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. In other cases you can only use the structure-* API. But never both. Bruno |