emacs.d/clones/lisp/colinallen.dnsalias.org/lp/node55.html

69 lines
2.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE> Strings</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Strings">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node56.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
<A HREF="node53.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
<A HREF="node54.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
<A HREF="lp.html"><B>Contents</B></A>
<B> Next:</B>
<A HREF="node56.html"> Defstruct</A>
<B>Up:</B>
<A HREF="node53.html"> ArraysVectors, and </A>
<B> Previous:</B>
<A HREF="node54.html"> Arrays and Vectors</A>
<BR> <HR> <P>
<H2> Strings</H2>
<P>
A string in Lisp is represented by characters surrounded by double quotes: <tt> &quot;</tt>. Strings are very useful for manipulating chunks of text. They are also used by Common Lisp to manage input and output.
<P>
Technically strings are arrays, but it is probably best (at first) to ignore this fact and treat them as a separate data type. Typing a string directly to the interpreter simply causes the interpreter to return the string:
<P>
<BLOCKQUOTE>
<PRE>&gt; &quot;This is a string&quot;
&quot;This is a string&quot;
</PRE>
</BLOCKQUOTE>
Notice that the string may contain spaces, and that the distinction between upper and lowercase letters is preserved. A string is completely opaque to the interpreter and may contain punctuation marks and even new lines:
<P>
<BLOCKQUOTE>
<PRE>&gt; &quot;This is a larger piece of text.
It contains a few, otherwise unmanageable
punctuation marks. It can even have blank lines:
^Like these!&quot;
&quot;This is a larger piece of text.
It contains a few, otherwise unmanageable
punctuation marks. It can even have blank lines:
^Like these!&quot;
</PRE>
</BLOCKQUOTE>
Strings can also be included as elements of lists. For example:
<P>
<BLOCKQUOTE>
<PRE>&gt; (cons &quot;this&quot; '(here))
(&quot;this&quot; HERE)
</PRE>
</BLOCKQUOTE>
Strings are very useful for giving nicely formatted responses to user commands. This will be explored in the next chapter.
<P>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>