339 lines
16 KiB
HTML
339 lines
16 KiB
HTML
![]() |
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>2.15. Overlap, Inclusion, and Disjointness of Types</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Overlap, Inclusion, and Disjointness of Types">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html2021 HREF="node43.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2019 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2015 HREF="node41.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2023 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2024 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html2022 HREF="node43.html"> Scope and Extent</A>
|
||
|
<B>Up:</B> <A NAME=tex2html2020 HREF="node15.html"> Data Types</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html2016 HREF="node41.html"> Unreadable Data Objects</A>
|
||
|
<HR> <P>
|
||
|
<H1><A NAME=SECTION006150000000000000000>2.15. Overlap, Inclusion, and Disjointness of Types</A></H1>
|
||
|
<P>
|
||
|
<A NAME=DATATYPERELATIONSHIPS>The</A>
|
||
|
Common Lisp data type hierarchy is tangled and purposely left somewhat
|
||
|
open-ended so that implementors may experiment with new data types
|
||
|
as extensions to the language. This section explicitly states all
|
||
|
the defined relationships between types, including subtype/supertype
|
||
|
relationships,
|
||
|
disjointness, and exhaustive partitioning. The user of Common Lisp
|
||
|
should not depend on any relationships not explicitly stated here.
|
||
|
For example, it is not valid to assume that because a number
|
||
|
is not complex and not rational that it must be a <tt>float</tt>, because
|
||
|
implementations are permitted to provide yet other kinds of numbers.
|
||
|
<P>
|
||
|
First we need some terminology.
|
||
|
If <i>x</i> is a supertype of <i>y</i>, then any object of type <i>y</i> is also
|
||
|
of type <i>x</i>, and <i>y</i> is said to be a subtype of <i>x</i>. If types
|
||
|
<i>x</i> and <i>y</i> are disjoint, then no object (in any implementation) may
|
||
|
be both of type <i>x</i> and of type <i>y</i>. Types <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap42265.gif"> through
|
||
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40275.gif"> are an <i>exhaustive union</i>
|
||
|
of type <i>x</i> if each <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40277.gif">
|
||
|
is a subtype of <i>x</i>, and any object of type <i>x</i> is
|
||
|
necessarily of at least one of the types <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40279.gif">;
|
||
|
<IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap42265.gif"> through <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40275.gif"> are furthermore an <i>exhaustive partition</i>
|
||
|
if they are also pairwise disjoint.
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The type <tt>t</tt> is a supertype of every type whatsoever.
|
||
|
Every object is of type <tt>t</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The type <tt>nil</tt> is a subtype of every type whatsoever.
|
||
|
No object is of type <tt>nil</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The types <tt>cons</tt>, <tt>symbol</tt>, <tt>array</tt>, <tt>number</tt>, and <tt>character</tt>
|
||
|
are pairwise disjoint.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in June 1988
|
||
|
(DATA-TYPES-HIERARCHY-UNDERSPECIFIED) <A NAME=1436> </A>
|
||
|
to extend the preceding paragraph as follows.
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The types <tt>cons</tt>, <tt>symbol</tt>, <tt>array</tt>, <tt>number</tt>, <tt>character</tt>,
|
||
|
<tt>hash-table</tt>, <tt>readtable</tt>, <tt>package</tt>, <tt>pathname</tt>,
|
||
|
<tt>stream</tt>, <tt>random-state</tt>, and any single other type created by
|
||
|
<tt>defstruct</tt> or <tt>defclass</tt>
|
||
|
are pairwise disjoint.
|
||
|
</UL>
|
||
|
<P>
|
||
|
The wording of the first edition was intended to allow implementors to use
|
||
|
the <tt>defstruct</tt> facility to define the built-in types <tt>hash-table</tt>,
|
||
|
<tt>readtable</tt>, <tt>package</tt>, <tt>pathname</tt>, <tt>stream</tt>, <tt>random-state</tt>.
|
||
|
The change still permits this implementation strategy but
|
||
|
forbids these built-in types from including, or being included in,
|
||
|
other types (in the sense of the <tt>defstruct</tt> <tt>:include</tt> option).
|
||
|
<P>
|
||
|
X3J13 voted in June 1988 (FUNCTION-TYPE) <A NAME=1463> </A>
|
||
|
to specify that the type <tt>function</tt>
|
||
|
is disjoint from the types <tt>cons</tt>, <tt>symbol</tt>, <tt>array</tt>, <tt>number</tt>, and <tt>character</tt>.
|
||
|
The type <tt>compiled-function</tt> is a subtype of <tt>function</tt>;
|
||
|
implementations are free to define other subtypes of <tt>function</tt>.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The types <tt>rational</tt>, <tt>float</tt>, and <tt>complex</tt> are pairwise disjoint
|
||
|
subtypes of <tt>number</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989 (REAL-NUMBER-TYPE) <A NAME=1483> </A> to rewrite the preceding item
|
||
|
as follows.
|
||
|
<UL><LI>
|
||
|
The types <tt>real</tt> and <tt>complex</tt> are pairwise disjoint
|
||
|
subtypes of <tt>number</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Rationale:</b> It might be thought that <tt>real</tt> and <tt>complex</tt> should
|
||
|
form an exhaustive partition of the type <tt>number</tt>. This is purposely
|
||
|
avoided here in order to permit compatible experimentation with extensions
|
||
|
to the Common Lisp number system.
|
||
|
<hr> <P>
|
||
|
<UL><LI>
|
||
|
The types <tt>rational</tt> and <tt>float</tt> are pairwise disjoint
|
||
|
subtypes of <tt>real</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Rationale:</b> It might be thought that <tt>rational</tt> and <tt>float</tt> should
|
||
|
form an exhaustive partition of the type <tt>real</tt>. This is purposely
|
||
|
avoided here in order to permit compatible experimentation with extensions
|
||
|
to the Common Lisp number system.
|
||
|
<hr>
|
||
|
<img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<UL><LI>
|
||
|
The types <tt>integer</tt> and <tt>ratio</tt> are disjoint subtypes of <tt>rational</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Rationale:</b> It might be thought that <tt>integer</tt> and <tt>ratio</tt> should
|
||
|
form an exhaustive partition of the type <tt>rational</tt>. This is purposely
|
||
|
avoided here in order to permit compatible experimentation with extensions
|
||
|
to the Common Lisp rational number system.
|
||
|
<hr>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The types <tt>fixnum</tt> and <tt>bignum</tt> are disjoint subtypes of <tt>integer</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Rationale:</b> It might be thought that <tt>fixnum</tt> and <tt>bignum</tt> should
|
||
|
form an exhaustive partition of the type <tt>integer</tt>. This is purposely
|
||
|
avoided here in order to permit compatible experimentation with
|
||
|
extensions to the Common Lisp integer number system, such as the idea of
|
||
|
adding explicit representations of infinity or of positive and negative
|
||
|
infinity.
|
||
|
<hr>
|
||
|
<br><img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in January 1989
|
||
|
(FIXNUM-NON-PORTABLE) <A NAME=1528> </A>
|
||
|
to specify that the types <tt>fixnum</tt> and <tt>bignum</tt>
|
||
|
do in fact form an exhaustive partition of the type <tt>integer</tt>; more precisely,
|
||
|
they voted to specify that the type <tt>bignum</tt> is by definition equivalent
|
||
|
to <tt>(and integer (not fixnum))</tt>. This is consistent with the
|
||
|
first edition text in section <A HREF="node17.html#INTEGERSSECTION">2.1.1</A>.
|
||
|
<P>
|
||
|
I interpret this to mean that implementators could still experiment with
|
||
|
such extensions as adding explicit representations of infinity, but such infinities
|
||
|
would necessarily be of type <tt>bignum</tt>.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The types <tt>short-float</tt>, <tt>single-float</tt>, <tt>double-float</tt>, and
|
||
|
<tt>long-float</tt> are subtypes of <tt>float</tt>. Any two of them must be
|
||
|
either disjoint or identical; if identical, then any other types between
|
||
|
them in the above ordering must also be identical to them
|
||
|
(for example, if <tt>single-float</tt> and <tt>long-float</tt> are identical types,
|
||
|
then <tt>double-float</tt> must be identical to them also).
|
||
|
<P>
|
||
|
<LI>
|
||
|
The type <tt>null</tt> is a subtype of <tt>symbol</tt>; the only object of type
|
||
|
<tt>null</tt> is <tt>nil</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The types <tt>cons</tt> and <tt>null</tt> form an exhaustive partition of the type
|
||
|
<tt>list</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The type <tt>standard-char</tt> is a subtype of <tt>string-char</tt>;
|
||
|
<tt>string-char</tt> is a subtype of <tt>character</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989 (CHARACTER-PROPOSAL) <A NAME=1563> </A> to remove the type <tt>string-char</tt>.
|
||
|
The preceding item is replaced by the following.
|
||
|
<UL><LI>
|
||
|
The type <tt>standard-char</tt> is a subtype of <tt>base-character</tt>.
|
||
|
The types <tt>base-character</tt> and <tt>extended-character</tt>
|
||
|
form an exhaustive partition of <tt>character</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The type <tt>string</tt> is a subtype of <tt>vector</tt>, for <tt>string</tt>
|
||
|
means <tt>(vector string-char)</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989 (CHARACTER-PROPOSAL) <A NAME=1582> </A> to remove the type <tt>string-char</tt>.
|
||
|
The preceding item is replaced by the following.
|
||
|
<UL><LI>
|
||
|
The type <tt>string</tt> is a subtype of <tt>vector</tt>; it is the union of
|
||
|
all types <tt>(vector <i>c</i>)</tt> such that <i>c</i> is a subtype of <tt>character</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The type <tt>bit-vector</tt> is a subtype of <tt>vector</tt>, for <tt>bit-vector</tt>
|
||
|
means <tt>(vector bit)</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The types <tt>(vector t)</tt>, <tt>string</tt>, and <tt>bit-vector</tt> are disjoint.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The type <tt>vector</tt> is a subtype of <tt>array</tt>; for all types <i>x</i>,
|
||
|
the type <tt>(vector <i>x</i>)</tt> is the same as the type <tt>(array <i>x</i> (*))</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The type <tt>simple-array</tt> is a subtype of <tt>array</tt>.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
The types <tt>simple-vector</tt>, <tt>simple-string</tt>, and
|
||
|
<tt>simple-bit-vector</tt> are disjoint subtypes of <tt>simple-array</tt>, for they
|
||
|
respectively mean <tt>(simple-array t (*))</tt>, <tt>(simple-array string-char (*))</tt>,
|
||
|
and <tt>(simple-array bit (*))</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989 (CHARACTER-PROPOSAL) <A NAME=1620> </A> to remove the type <tt>string-char</tt>.
|
||
|
The preceding item is replaced by the following.
|
||
|
<UL><LI>
|
||
|
The types <tt>simple-vector</tt>, <tt>simple-string</tt>, and
|
||
|
<tt>simple-bit-vector</tt> are disjoint subtypes of <tt>simple-array</tt>, for they
|
||
|
mean <tt>(simple-array t (*))</tt>, the union of all types
|
||
|
<tt>(simple-array <i>c</i> (*))</tt> such that <i>c</i> is a subtype of <tt>character</tt>,
|
||
|
and <tt>(simple-array bit (*))</tt>, respectively.
|
||
|
</UL>
|
||
|
<img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The type <tt>simple-vector</tt> is a subtype of <tt>vector</tt> and indeed
|
||
|
is a subtype of <tt>(vector t)</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The type <tt>simple-string</tt> is a subtype of <tt>string</tt>.
|
||
|
(Note that although <tt>string</tt> is a subtype of <tt>vector</tt>,
|
||
|
<tt>simple-string</tt> is not a subtype of <tt>simple-vector</tt>.)
|
||
|
</UL>
|
||
|
<P>
|
||
|
<hr>
|
||
|
<b>Rationale:</b> The hypothetical name <tt>simple-general-vector</tt> would have been more accurate than
|
||
|
<tt>simple-vector</tt>, but in this instance euphony and
|
||
|
user convenience were deemed more important to the design
|
||
|
of Common Lisp than a rigid symmetry.
|
||
|
<hr><P>
|
||
|
<UL><LI>
|
||
|
The type <tt>simple-bit-vector</tt> is a subtype of <tt>bit-vector</tt>.
|
||
|
(Note that although <tt>bit-vector</tt> is a subtype of <tt>vector</tt>,
|
||
|
<tt>simple-bit-vector</tt> is not a subtype of <tt>simple-vector</tt>.)
|
||
|
<P>
|
||
|
<LI>
|
||
|
The types <tt>vector</tt> and <tt>list</tt> are disjoint subtypes of <tt>sequence</tt>.
|
||
|
<P>
|
||
|
<LI>
|
||
|
The types <tt>random-state</tt>, <tt>readtable</tt>, <tt>package</tt>, <tt>pathname</tt>,
|
||
|
<tt>stream</tt>, and <tt>hash-table</tt> are pairwise disjoint.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in June 1988
|
||
|
(DATA-TYPES-HIERARCHY-UNDERSPECIFIED) <A NAME=1667> </A>
|
||
|
to make <tt>random-state</tt>, <tt>readtable</tt>, <tt>package</tt>, <tt>pathname</tt>,
|
||
|
<tt>stream</tt>, and <tt>hash-table</tt>
|
||
|
pairwise disjoint from a number of other types as well;
|
||
|
see note above.
|
||
|
<P>
|
||
|
X3J13 voted in January 1989
|
||
|
(STREAM-ACCESS) <A NAME=1676> </A>
|
||
|
to introduce subtypes of type <tt>stream</tt>.
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
The types <tt>two-way-stream</tt>, <tt>echo-stream</tt>,
|
||
|
<tt>broadcast-stream</tt>, <tt>file-stream</tt>, <tt>synonym-stream</tt>, <tt>string-stream</tt>, and
|
||
|
<tt>concatenated-stream</tt> are disjoint subtypes of <tt>stream</tt>.
|
||
|
</UL>
|
||
|
<img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<UL><LI>
|
||
|
Any two types created by <tt>defstruct</tt> are disjoint unless
|
||
|
one is a supertype of the other by virtue of
|
||
|
the <tt>:include</tt> option.
|
||
|
</UL>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<UL><LI>
|
||
|
An exhaustive union for the type <tt>common</tt> is formed by the types
|
||
|
<tt>cons</tt>, <tt>symbol</tt>, <tt>(array <i>x</i>)</tt> where <i>x</i> is either <tt>t</tt> or
|
||
|
a subtype
|
||
|
of <tt>common</tt>, <tt>string</tt>, <tt>fixnum</tt>, <tt>bignum</tt>, <tt>ratio</tt>,
|
||
|
<tt>short-float</tt>, <tt>single-float</tt>, <tt>double-float</tt>, <tt>long-float</tt>,
|
||
|
<tt>(complex <i>x</i>)</tt> where <i>x</i> is a
|
||
|
subtype of <tt>common</tt>,
|
||
|
<tt>standard-char</tt>, <tt>hash-table</tt>, <tt>readtable</tt>, <tt>package</tt>, <tt>pathname</tt>,
|
||
|
<tt>stream</tt>, <tt>random-state</tt>, and all types created by the user
|
||
|
via <tt>defstruct</tt>.
|
||
|
An implementation may not unilaterally add subtypes to
|
||
|
<tt>common</tt>; however, future revisions to the Common Lisp standard may
|
||
|
extend the definition of the <tt>common</tt> data type.
|
||
|
Note that a type such as <tt>number</tt> or <tt>array</tt> may or may
|
||
|
not be a subtype of <tt>common</tt>, depending on whether or not the given
|
||
|
implementation has extended the set of objects of that type.
|
||
|
</UL>
|
||
|
<img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in March 1989
|
||
|
(COMMON-TYPE) <A NAME=1729> </A>
|
||
|
to remove the type <tt>common</tt> from the language.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html2021 HREF="node43.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2019 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2015 HREF="node41.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2023 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2024 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html2022 HREF="node43.html"> Scope and Extent</A>
|
||
|
<B>Up:</B> <A NAME=tex2html2020 HREF="node15.html"> Data Types</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html2016 HREF="node41.html"> Unreadable Data Objects</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|