[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patches to typep???



    Date: Fri 21 Aug 87 15:15:34-PST
    From: Doug Ruth <RUTH@sri-robotx.arpa>

    Similarly for structures if I type:

    (defstruct newstruct (a 0.0 :type 'float))
    (defvar *s1*)
    (setf *s1* (make-newstruct))
    (typep *s1* 'newstruct)  =====> returns T

    which is what I want, but then I can assign an object of some other type to 
    slot a of *s1* and it still returns T:

    (setf (newstruct-a *s1*) 'red)

The behavior of this last form is undefined.  You seem to misunderstand
the :TYPE slot option.  It is a declaration that your program will not
store anything but the specified type in the slot, which the compiler
may choose to base optimizations on (for example, it knows a priori that
(* (newstruct-a *s1*) (newstruct-a *s2*)) can use floating point
multiplication).  It is NOT a type restriction.  It is as error to
assign a non-float to slot A of NEWSTRUCT; however, it is not required
that implementations detect this error.

    (typep *s1* 'newstruct)  =====> returns T

    I would like (typep ) to check the contents of the slots of structures as 
    well.

It is not part of the contract of TYPEP to check whether you've stored
invalid values in structure slots.  As far as the portable language is
concerned, you aren't supposed to do this.

                                                barmar