>>>>> "Madhu" == Madhu  <enom...@meer.net> writes:

    Madhu> * Raymond Toy <sxd1vwg0znv....@rtp.ericsson.se> :
    Madhu> Wrote on Wed, 10 Dec 2008 11:21:08 -0500:

    Madhu> |>>>>> "dvl" == Didier Verna <didier.ve...@gmail.com> writes:

    Madhu> |     dvl> But doing so by making (setf (slot-value))'s behavior
    Madhu> |     dvl> different (shall I say inconsistent?) depending on the
    Madhu> |     dvl> context feels somewhat weird to
    Madhu> |
    Madhu> |     Raymond> Yes, I think it's inconsistent.
    Madhu> |
    Madhu> |     dvl> me. I guess you concern is performance here; but then, we 
can
    Madhu> |     dvl> play with the optimize declaration.

    Madhu> The other concern was compatibility with other lisps which do not 
signal
    Madhu> an error when the type declaration is wrong.  This particular 
typecheck
    Madhu> is not mandated by any spec, and lisps tend to let it pass.

Perhaps, but cmucl has always complained about stuff like this (when
compiled):

    (defun foo (x) (declare (double-float x)) (sin x))

    (foo 42)

Also, I want to make it a bit clearer.  In the test case:

    (defclass foo2 ()
      ((slot :type single-float :initform 1.2f0)
       (slot2)))

    (defclass bar ()
      ((a :type fixnum :initform 0)))

    (defparameter *o* (make-instance 'foo2))

    (defmethod setslot ((obj bar) val)
      (setf (slot-value *o* 'slot) val)
      (setf (slot-value obj 'a) val))

Then (setslot (make-instance 'bar) 42) does not signal an error when
assigning a fixnum to the single-float slot of class foo2.  But
(setslot (make-instance 'bar) "abc") does signal an error about
assigning a string to a fixnum in the bar object.  The difference is
that obj is an argument to the method.  I think this has been this way
ever since Gerd added this ability.

The change I made was mostly for calling (setf slot-value) from the
repl.  Perhaps the example above should also signal an error (if
safety is low enough).  I don't know how to do either (signal an error
for *o* or make it not signal an error if safety is low enough).

    Madhu> | Perhaps not the best solution, but I have made an internal change 
so
    Madhu> | that pcl::*use-slot-type-p* will be honored (at runtime).  Hence, 
type
    Madhu> | checking will be done accordingly.

    Madhu> Thanks, I have no problems setting pcl::*use-slot-types-p* when
    Madhu> compiling code with incorrect typespecs but thinking out aloud [on
    Madhu> behalf of the devil] perhaps the default behaviour should be a 
warning

That would go against long-standing history of CMUCL signaling errors
for type issues.  (Even if PCL historically didn't do this kind of
type checking until Gerd added it.)

Ray

Reply via email to