Common Lisp the Language 2nd Edition


next up previous contents index
Next: Type Specifiers That Up: Type Specifiers Previous: Type Specifiers That

4.5. Type Specifiers That Specialize

Some type specifier lists denote specializations of data types named by symbols. These specializations may be reflected by more efficient representations in the underlying implementation. As an example consider the type (array short-float). Implementation A may choose to provide a specialized representation for arrays of short floating-point numbers and implementation B may choose not to.

If you should want to create an array for the express purpose of holding only short-float objects you may optionally specify to make-array the element type short-float. This does not require make-array to create an object of type (array short-float); it merely permits it. The request is construed to mean ``Produce the most specialized array representation capable of holding short-floats that the implementation can provide.'' Implementation A will then produce a specialized array of type (array short-float) and implementation B will produce an ordinary array of type (array t).

If one were then to ask whether the array were actually of type (array short-float) implementation A would say ``yes '' but implementation B would say ``no.'' This is a property of make-array and similar functions: what you ask for is not necessarily what you get.

old_change_begin
Types can therefore be used for two different purposes: declaration and discrimination. Declaring to make-array that elements will always be of type short-float permits optimization. Similarly declaring that a variable takes on values of type (array short-float) amounts to saying that the variable will take on values that might be produced by specifying element type short-float to make-array. On the other hand if the predicate typep is used to test whether an object is of type (array short-float) whether an object is of type (array short-float)y specifyingarrayhe/H1>ons/next_motif.gif">