90 lines
4.8 KiB
HTML
90 lines
4.8 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.5.2. Strings</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Strings">
|
||
|
<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=tex2html1893 HREF="node32.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1891 HREF="node29.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1885 HREF="node30.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1895 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1896 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1894 HREF="node32.html"> Bit-Vectors</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1892 HREF="node29.html"> Arrays</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1886 HREF="node30.html"> Vectors</A>
|
||
|
<HR> <P>
|
||
|
<H2><A NAME=SECTION00652000000000000000>2.5.2. Strings</A></H2>
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
<A NAME=STRINGTYPESECTION>A</A>
|
||
|
string is simply a vector of characters.
|
||
|
More precisely, a string is a specialized vector whose elements
|
||
|
are of type <tt>string-char</tt>.
|
||
|
<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 March 1989 (CHARACTER-PROPOSAL) <A NAME=1261> </A>
|
||
|
to eliminate the type <tt>string-char</tt> and to redefine the type
|
||
|
<tt>string</tt> to be the union of one or more specialized vector
|
||
|
types, the types of whose elements are subtypes of the type <tt>character</tt>.
|
||
|
Subtypes of <tt>string</tt> include <tt>simple-string</tt>, <tt>base-string</tt>,
|
||
|
and <tt>simple-base-string</tt>.
|
||
|
<P>
|
||
|
<P><pre>
|
||
|
base-string == (vector base-character)
|
||
|
simple-base-string == (simple-array base-character (*))
|
||
|
</pre><P>
|
||
|
An implementation may support
|
||
|
other string subtypes as well. All Common Lisp functions that operate
|
||
|
on strings treat all strings uniformly; note, however,
|
||
|
that it is an error to attempt to insert
|
||
|
an extended character into a base string.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
The type <tt>string</tt> is therefore a subtype of the type <tt>vector</tt>.
|
||
|
<P>
|
||
|
A string can be written as the sequence of characters contained in the
|
||
|
string, preceded and followed by a <tt>"</tt> (double quote) character.
|
||
|
Any <tt>"</tt> or <tt>\</tt> character in the sequence must additionally
|
||
|
have a <tt>\</tt> character before it.
|
||
|
<P>
|
||
|
For example:
|
||
|
<P>
|
||
|
<P><pre>
|
||
|
"Foo" ;A string with three characters in it
|
||
|
"" ;An empty string
|
||
|
"\"APL\\360?\" he cried." ;A string with twenty characters
|
||
|
"|x| = |-x|" ;A ten-character string
|
||
|
</pre><P>
|
||
|
Notice that any vertical bar <tt>|</tt> in a string need not be
|
||
|
preceded by a <tt>\</tt>. Similarly, any double quote in the name
|
||
|
of a symbol written using vertical-bar notation need not be
|
||
|
preceded by a <tt>\</tt>. The double-quote and vertical-bar notations
|
||
|
are similar but distinct: double quotes indicate a character string
|
||
|
containing the sequence of characters,
|
||
|
whereas vertical bars indicate a symbol whose name is the contained
|
||
|
sequence of characters.
|
||
|
<P>
|
||
|
The characters contained by the double quotes, taken from left to right,
|
||
|
occupy locations within the string with increasing indices.
|
||
|
The leftmost character is string element number 0, the next one
|
||
|
is element number 1, the next one is element number 2, and so on.
|
||
|
<P>
|
||
|
Note that the function <tt>prin1</tt> will print any character vector
|
||
|
(not just a simple one)
|
||
|
using this syntax, but the function <tt>read</tt> will always construct
|
||
|
a simple string when it reads this syntax.
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html1893 HREF="node32.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1891 HREF="node29.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1885 HREF="node30.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1895 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1896 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1894 HREF="node32.html"> Bit-Vectors</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1892 HREF="node29.html"> Arrays</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1886 HREF="node30.html"> Vectors</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|