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

Category Errors



    Date: 08 Jul 87  0938 PDT
    From: Dick Gabriel <RPG@SAIL.STANFORD.EDU>

    Suppose that MAKE-INSTANCE is a generic function. Its definition
    might look like this:

	    (defmethod make-instance ((class standard-class) &rest args)...)

    Notice that the class of the argument CLASS is STANDARD-CLASS, which
    indicates that the operation of MAKE-INSTANCE is controlled at the
    meta-object level. Suppose someone were to write:

	    (defmethod make-instance ((class apple-pie) &rest args)...)

I don't think this is fundamentally different from someone defining
a method on spaceships for a generic function that is only supposed to
be used with windows.  The only reason I can see that confusion between
classes and metaclasses seems worse than confusion between spaceships
and windows is that metaclasses are less familiar.

If we didn't want to follow the usual Lisp philosophy of giving the
user enough rope to hang himself, we could add a feature such as the
following

  (defgeneric-options make-instance (class &rest initargs)
    (:parameter-specializer-restriction class (or class symbol)))

which says methods can't be defined with a parameter specializer for
the first parameter (named class) that isn't a subtype of (or class symbol).
Using the type system to express the restriction, rather than inventing
a new concept of levels, seems both more general and easier to understand.
However, I don't really think we want to add this kind of restriction, at
least, it wouldn't be consistent with the minimalist design criterion
we have used elsewhere in CLOS.