In some auto generated code, I got something like
(defstruct s
(p 0d0 :type double-float))
What is supposed to happen now? S-P is supposed to be the predicate
for the structure S. However S-P is also supposed to the accessor to
the slot P. I guess what S-P means depends on which gets defined
last: the predicate or the accessor.
The obvious work around is to give an explicit predicate option, like
is-s-p, which can't possibly be a slot accessor name for this struct
or to change the name of the slot.
Ray
Raymond Toy <ยทยทยท@rtp.ericsson.se> writes:
> In some auto generated code, I got something like
>
> (defstruct s
> (p 0d0 :type double-float))
>
> What is supposed to happen now? S-P is supposed to be the predicate
> for the structure S. However S-P is also supposed to the accessor to
> the slot P. I guess what S-P means depends on which gets defined
> last: the predicate or the accessor.
One data point:
Under Allegro CL Trial Edition 5.0 [Linux/X86] S-P is the predicate.
No warnings were given.
No idea if this is "correct".
Stig Hemmer,
Jack of a Few Trades.
Someone should notify Franz on this point. I can see this particular point
causing hours of wasted time some day.
Anyway, in ACL (since it uses the MOP), you can access defstruct slots with
'slot-value', so even if s-p was the predicate, you can still access the p
slot with:
(slot-value struct-instance 'p)
Of course, this is surely non-portable, but realistically, what does portable
mean for Lisp? There arn't enough Lisps to make writing portable code so
important. I personall wouldn't want to use an implementation that didn't use
the MOP, and extended functionality to structs.
dave