Note that the argument :ELEMENT-TYPE for MAKE-ARRAY does something special, and its exact behavior may be a bit unexpected.
Using this, you tell Common Lisp that ARRAY should be able to store elements of this type of element or some of its subtypes.
Then the Common Lisp system returns an array that can store these elements. It can be a specialized array or an array that can also store more general elements.
Note that this is not a type declaration, and it will not necessarily be checked at compile time or at run time.
The UPGRADED-ARRAY-ELEMENT-TYPE function tells you which item can actually be updated.
LispWorks 64bit:
CL-USER 10 > (upgraded-array-element-type '(unsigned-byte 8)) (UNSIGNED-BYTE 8) CL-USER 11 > (upgraded-array-element-type '(unsigned-byte 4)) (UNSIGNED-BYTE 4) CL-USER 12 > (upgraded-array-element-type '(unsigned-byte 12)) (UNSIGNED-BYTE 16)
So, Lispworks 64bit has special arrays for 4 and 8 bit elements. For 12-bit elements, it allocates an array that can store up to 16 bit elements.
We generate an array that can store ten numbers up to 12 bits:
CL-USER 13 > (make-array 10 :element-type '(unsigned-byte 12) :initial-element 0) #(0 0 0 0 0 0 0 0 0 0)
Let me check its type:
CL-USER 14 > (type-of *) (SIMPLE-ARRAY (UNSIGNED-BYTE 16) (10))
This is a simple array (not adjustable, without padding). It can store elements of type (UNSIGNED-BYTE 16) and its subtypes. It has a length of 10 and has one size.
Rainer joswig
source share