next up previous
Contents Next: Defstruct Up: ArraysVectors, and Previous: Arrays and Vectors

Strings

A string in Lisp is represented by characters surrounded by double quotes: ". Strings are very useful for manipulating chunks of text. They are also used by Common Lisp to manage input and output.

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:

> "This is a string"
"This is a string"
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:

> "This is a larger piece of text.
It contains a few, otherwise unmanageable
punctuation marks.  It can even have blank lines:



^Like these!"
"This is a larger piece of text.
It contains a few, otherwise unmanageable
punctuation marks.  It can even have blank lines:



^Like these!"
Strings can also be included as elements of lists. For example:

> (cons "this" '(here))
("this" HERE)
Strings are very useful for giving nicely formatted responses to user commands. This will be explored in the next chapter.



© Colin Allen & Maneesh Dhagat
March 2007