Re: [cmucl-imp] Re: When slots :type are used

Raymond Toy <[email protected]>
Newsgroups gmane.lisp.cmucl.general
Message-ID <[email protected]>
>>>>> "Madhu" == Madhu  <[email protected]> writes:

    Madhu> * Raymond Toy <[email protected]> :
    Madhu> Wrote on Wed, 10 Dec 2008 11:21:08 -0500:

    Madhu> |>>>>> "dvl" == Didier Verna <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.