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

Re: [kempf%Sun:COM:Xerox: CLOS Slot Subclassing Rule Violates Contravariance]



    But the very least one would expect from the type system in an
    object-oriented language is that it would enable you to write code
    that didn't get a no matching method message at run time.

In our original discussion of accessors and types, I remember that the
model proposed was that:

(defclass foo ()
  ((bar :type baz :accessor foo-bar)))

would, if type checking were to be enforced in the accessors,  generate a
method equivalent to:

(defmethod (setf foo-bar) (new-value (inst foo))
   (check-type inst 'baz)
   (setf (slot-value inst bar) new-value))

This would give the expected error message.

There is a general confusion in the use of CLOS about whether
specialization of arguments should be used for type checking.  My take is
that these discrimination and type checking should be separated.  But it is
convenient to have type declarations in the header.  However, is easy to
make a special defining form, e.g.

(define-checked-method ((:check new-value baz) (inst foo))
      (setf (slot-value inst bar) new-value))

that expands into the definition above.  One might use the checking syntax
in optionals and keyword positions as well.