>>108502952
For CLOS method dispatching, you can only dispatch on classes or eql specifiers, not types in general, so you can't dispatch on the type of the inner elements. Maybe it's possible to use the MOP to get some support for this, but if it's similar to manually doing it with a typecase on array-element-type it won't really work in general either. That's because while you can specify the inner type in make-array, there's not consistent enforcement to ensure all elements remain the same type, the inner type may be upgrade to T regardless. Specifying the inner type is mostly useful for optimization cases with double-floats or uints.
(let ((a (make-array 3 :element-type 'double-float)))
(setf (aref a 0) "a")
(list a (array-element-type a) (type-of a)))
In SBCL this will error. Take out the setf and it'll initialize the elements to 0.0d0 for you. But change the type to float, it'll be a warning that the initial elements aren't floats, but the setf works and array-element-type will be T. Add :initial-element 0.0 to remove the warning but the inner type is still T. Integer works, no warning. Character, error. (unsigned-byte 8), error. Symbol, warning about initial-element but works.
You can add an :after method if you want to make sure the return values of all of these ends up as a string, though it'd be better to just fix the one method that's odd.
Note that if you use Coalton you can dispatch on inner element types as well as return types using typeclasses.
Or you can use this helper library from numcl if you want some support for numeric inner type specialization https://github.com/numcl/specialized-function