Strings(字符串)
如前所述,Common Lisp 中的字符串其实是一种复合数据类型,也即一个一维字符数组。因此,我将在下一章讨论用来处理序列的许多函数时将谈及许多字符串应用,因为字符串只不过是一种序列。但字符串也有其自己的字面语法和一个用来进行字符串特定操作的函数数库。本章将讨论字符串的这些方面并将其余部分留到第 11 章再作介绍。
As you’ve seen, literal strings are written enclosed in double quotes. You can include any character supported by the character set in a literal string except double quote () and backslash (\
). And you can include these two as well if you escape them with a backslash. In fact, backslash always escapes the next character, whatever it is, though this isn’t necessary for any character except for "
and itself. Table 10-2 shows how various literal strings will be read by the Lisp reader.
Note that the REPL will ordinarily print strings in readable form, adding the enclosing quotation marks and any necessary escaping backslashes, so if you want to see the actual contents of a string, you need to use function such as FORMAT designed to print human-readable output. For example, here’s what you see if you type a string containing an embedded quotation mark at the REPL:
FORMAT, on the other hand, will show you the actual string contents:
另一方面,FORMAT 将显示出实际的字符串内容: