Common Lisp the Language, 2nd Edition
Next: Program Structure
Up: Type Specifiers
Previous: Determining the
Type
X3J13 voted in January 1989 (ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS) to add new functions by which a program can determine, in a given Common Lisp implementation, how that implementation will upgrade a type when constructing an array specialized to contain elements of that type, or a complex number specialized to contain parts of that type.
[Function]
upgraded-array-element-type
type
A type specifier is returned, indicating the element type of the most
specialized array representation capable of holding items of the
specified argument type. The result is necessarily a supertype
of the given type. Furthermore, if a type A is a
subtype of type B, then
(upgraded-array-element-type
A
)
is a subtype of
(upgraded-array-element-type
B
)
.
The manner in which an array element type is upgraded depends only on the element type as such and not on any other property of the array such as size, rank, adjustability, presence or absence of a fill pointer, or displacement.
Rationale: If upgrading were allowed to depend on
any of these properties, all of which can be referred to, directly or
indirectly, in the language of type specifiers, then it would not be
possible to displace an array in a consistent and dependable manner to
another array created with the same :element-type
argument
but differing in one of these properties.
Note that upgraded-array-element-type
could be defined
as
(defun upgraded-array-element-type (type)
(array-element-type (make-array 0 :element-type type)))
but this definition has the disadvantage of allocating an array and then immediately discarding it. The clever implementor surely can conjure up a more practical approach.
[Function]
upgraded-complex-part-type
type
A type specifier is returned, indicating the element type of the most
specialized complex number representation capable of having parts of the
specified argument type. The result is necessarily a supertype
of the given type. Furthermore, if a type A is a
subtype of type B, then
(upgraded-complex-part-type
A
)
is a subtype of
(upgraded-complex-part-type
B
)
.
Next: Program Structure
Up: Type Specifiers
Previous: Determining the
Type
AI.Repository@cs.cmu.edu