In Common Lisp, you can’t do this:
(defgeneric g (x)) (defmethod g ((x (and integer (satisfies evenp))) ...)
Because (and integer ...)
is not a class. It is a valid type specifier and thus could be used in declarations, but it cannot be used in a method argument list.
It’s fairly easy to see why this is the case: allowing compound type specifiers in method argument lists effectively means creating anonymous classes on-the-fly, which would play havoc with the type hierarchies on which method dispatch depends.
But why can’t we unify types and classes? Every CLOS class has a corresponding type of the same name, and the built-in types are also classes. Furthermore, it is fairly obvious that (and integer (satisfies evenp))
is a sub-type of integer
, so why not go ahead and treat it like a class that inherits from integer
?