(let ((a (make-array 10 :element-type 'float)))
(typep a 'simple-vector))
T
(let ((a (make-array 10 :element-type 'single-float)))
(typep a 'simple-vector))
NIL
So, a vector whose elements type is 'single-float is not a simple
vector?. However, it is a simple-array
(let ((a (make-array 10 :element-type 'single-float)))
(typep a 'simple-array))
T
where could I find the rationale for this?
Josep Riverola
IESE
Camino del Cerro del Aguila 10
Madrid 28023-Spain
mailto:rive...@iese.es
Josep Riverola
To address this, MCL can create some array types which store elements of the same king in a more efficient way. What you have seen is that an array of floats is created as the more general type of vector. MCL needs to do this because a float can either be a single or double float (which are the same thing in MCL) - taking 8 bytes, or a short-float, which take 4 bytes. When you are asking for an array of short-float, MCL knows that each element take 4 bytes, and creates a specialized array accordingly. The same thing would happen if you made an array of double-floats (or equivalent single-floats). When you ask for something that could be both, MCL punts and just makes the most general type of array.
The reason one is of type 'simple-array but not 'simple-vector is that simple-array is a more general type than vector or simple-vector. A simple vector is an array when each element can be any lisp object.
You can see this by inspecting the class precedence list for (find-class 'simple-vector)
simple-vector
general-vector
simple-1d-array
vector
simple-array
array
sequence
t
So all simple-vectors are simple-arrays, but not all simple-arrays (even of 1 dimension) are simple-vectors. A little more understandable is
(setq a (make-array 10 :element-type 'single-float))
(typep a 'vector) -> t
(array-element-type a) -> double-float
(typep a 'simple-vector) -> nil ;; not simple because elements are only double-floats
(setq a (make-array 10 :element-type 'float))
(typep a 'vector) -> t
(array-element-type a) -> t
(typep a 'simple-vector) -> t ;; simple because MCL makes an array that can hold any value.
Hope this helps,
Alan