[Openmcl-devel] defmethod parameter specializers

Gary Byers gb at clozure.com
Sat Aug 13 10:14:21 UTC 2005


CLASS-OF is returning the builtin ARRAY class for all multidimensional
arrays.  It returns a builtin SIMPLE-ARRAY class in some other
implementations (and that's in some cases more useful), but I'm not
sure that you can portably assume that it does. Figure 4.8 in CLHS
4.3.7 lists the classes that correspond to pre-defined type specifiers,
and SIMPLE-ARRAY is conspicuously absent from that list; SIMPLE-ARRAY
isn't designated by the spec to be a "system class", and whether arrays
with certain attributes are SIMPLE-ARRAYs or not is implementation
dependent.

It wouldn't be hard (and it'd be perfectly legal) to change CLASS-OF
to return #<BUILTIN-CLASS SIMPLE-ARRAY> (or a subclass of that class)
for all arrays that are SIMPLE-ARRAYs in OpenMCL (it in fact does so
for vectors).  Using SIMPLE-ARRAY as a method specializer to denote
"arrays that are SIMPLE-ARRAYS in the current implementation" might be
somewhat useful, but wouldn't necessarily be portable:


(defmethod classify ((a array))
   (format t "Just a random array: ~s" a))

(defmethod classify ((a simple-array))
   (format t "a SIMPLE-ARRAY:" ~s))

(classify (make-array 7 :fill-pointer 7))

Which method gets invoked in that example depends on whether vectors
with fill-pointers are SIMPLE-ARRAYs in the implementation.  (I don't
know offhand of any implementation where they are.)

That example might explain why SIMPLE-ARRAY is missing from Figure 4.8
(it's hard to use portably), but it may be simpler to change CLASS-OF
than to repeat this long explanation the next time the issue arises.



On Sat, 13 Aug 2005, Duncan Rose wrote:

>
> Is the following expected behaviour? I'm trying to create a method 
> specialized on (to?) a multi-dimensional array of unspecified dimensionality:
>
> CL-USER> (defgeneric my-test (collection))
> #<STANDARD-GENERIC-FUNCTION MY-TEST #x6509B46>
>
> CL-USER> (defmethod my-test ((collection t))
> 	   (format t "basic~%"))
> #<STANDARD-METHOD MY-TEST (T)>
>
> CL-USER> (defmethod my-test ((collection simple-array))
> 	   (format t "simple-array~%"))
> #<STANDARD-METHOD MY-TEST (SIMPLE-ARRAY)>
>
> CL-USER> (my-test #2A(('a 'b) ('c 'd)))
> basic
> NIL
>
> CL-USER> (subtypep '(simple-array t (* *)) 'simple-array)
> T
> T
> CL-USER> (typep #2A(('a 'b) ('c 'd)) 'simple-array)
> T
> CL-USER> (find-class 'simple-array)
> #<BUILT-IN-CLASS SIMPLE-ARRAY>
>
> CL-USER>
>
>
> Shouldn't the call (my-test #2A(...)) invoke the method specializing the 
> parameter to simple-array since simple-array is more specific than T?
>
> I'm using 0.14.3 on 10.2
>
> -Duncan
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list