File: LISP-tutorial-14.html

package info (click to toggle)
cmucl 20c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 42,524 kB
  • sloc: lisp: 358,331; ansic: 28,385; asm: 3,777; sh: 1,236; makefile: 366; csh: 31
file content (59 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<HTML>
<HEAD>
<TITLE>Common LISP Hints: Strings</TITLE>
</HEAD>
<BODY>
<A HREF="LISP-tutorial-13.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-15.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc14"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s14">14. Strings</A></H2>

<P>A string is a sequence of characters between double quotes. LISP
represents a string as a variable-length array of characters. You can
write a string which contains a double quote by preceding the quote
with a backslash; a double backslash stands for a single backslash. For
example:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&quot;abcd&quot; has 4 characters
&quot;\&quot;&quot; has 1 character
&quot;\\&quot; has 1 character
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>Here are some functions for dealing with strings:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (concatenate 'string &quot;abcd&quot; &quot;efg&quot;)
&quot;abcdefg&quot;
&gt; (char &quot;abc&quot; 1)
#\b                     ;LISP writes characters preceded by #\
&gt; (aref &quot;abc&quot; 1)
#\b                     ;remember, strings are really arrays
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>The <CODE>concatenate</CODE> function can actually work with any type of sequence:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (concatenate 'string '(#\a #\b) '(#\c))
&quot;abc&quot;
&gt; (concatenate 'list &quot;abc&quot; &quot;de&quot;)
(#\a #\b #\c #\d #\e)
&gt; (concatenate 'vector '#(3 3 3) '#(3 3 3))
#(3 3 3 3 3 3)
</PRE>
</CODE></BLOCKQUOTE>
</P>


<HR>
<A HREF="LISP-tutorial-13.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-15.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc14"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>