Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Bit-Vectors Up: Arrays Previous: Vectors

2.5.2. Strings

old_change_begin
A string is simply a vector of characters. More precisely, a string is a specialized vector whose elements are of type string-char.
old_change_end

change_begin
X3J13 voted in March 1989 (CHARACTER-PROPOSAL)   to eliminate the type string-char and to redefine the type string to be the union of one or more specialized vector types, the types of whose elements are subtypes of the type character. Subtypes of string include simple-string, base-string, and simple-base-string.

base-string == (vector base-character) 
simple-base-string == (simple-array base-character (*))

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.
change_end

The type string is therefore a subtype of the type vector.

A string can be written as the sequence of characters contained in the string, preceded and followed by a " (double quote) character. Any " or \ character in the sequence must additionally have a \ character before it.

For example:

"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

Notice that any vertical bar | in a string need not be preceded by a \. Similarly, any double quote in the name of a symbol written using vertical-bar notation need not be preceded by a \. 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.

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.

Note that the function prin1 will print any character vector (not just a simple one) using this syntax, but the function read will always construct a simple string when it reads this syntax.



next up previous contents index
Next: Bit-Vectors Up: Arrays Previous: Vectors


AI.Repository@cs.cmu.edu