1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: String Basics, Next: Predicates for Strings, Up: Strings and Characters
55 String and Character Basics
56 ===========================
58 Strings in XEmacs Lisp are arrays that contain an ordered sequence of
59 characters. Characters are their own primitive object type in XEmacs
60 20. However, in XEmacs 19, characters are represented in XEmacs Lisp as
61 integers; whether an integer was intended as a character or not is
62 determined only by how it is used. *Note Character Type::.
64 The length of a string (like any array) is fixed and independent of
65 the string contents, and cannot be altered. Strings in Lisp are _not_
66 terminated by a distinguished character code. (By contrast, strings in
67 C are terminated by a character with ASCII code 0.) This means that
68 any character, including the null character (ASCII code 0), is a valid
71 Since strings are considered arrays, you can operate on them with the
72 general array functions. (*Note Sequences Arrays Vectors::.) For
73 example, you can access or change individual characters in a string
74 using the functions `aref' and `aset' (*note Array Functions::).
76 Strings use an efficient representation for storing the characters
77 in them, and thus take up much less memory than a vector of the same
80 Sometimes you will see strings used to hold key sequences. This
81 exists for backward compatibility with Emacs 18, but should _not_ be
82 used in new code, since many key chords can't be represented at all and
83 others (in particular meta key chords) are confused with accented
86 Strings are useful for holding regular expressions. You can also
87 match regular expressions against strings (*note Regexp Search::). The
88 functions `match-string' (*note Simple Match Data::) and
89 `replace-match' (*note Replacing Match::) are useful for decomposing
90 and modifying strings based on regular expression matching.
92 Like a buffer, a string can contain extents in it. These extents are
93 created when a function such as `buffer-substring' is called on a
94 region with duplicable extents in it. When the string is inserted into
95 a buffer, the extents are inserted along with it. *Note Duplicable
98 *Note Text::, for information about functions that display strings or
99 copy them into buffers. *Note Character Type::, and *Note String
100 Type::, for information about the syntax of characters and strings.
103 File: lispref.info, Node: Predicates for Strings, Next: Creating Strings, Prev: String Basics, Up: Strings and Characters
105 The Predicates for Strings
106 ==========================
108 For more information about general sequence and array predicates,
109 see *Note Sequences Arrays Vectors::, and *Note Arrays::.
111 - Function: stringp object
112 This function returns `t' if OBJECT is a string, `nil' otherwise.
114 - Function: char-or-string-p object
115 This function returns `t' if OBJECT is a string or a character,
118 In XEmacs addition, this function also returns `t' if OBJECT is an
119 integer that can be represented as a character. This is because
120 of compatibility with previous XEmacs and should not be depended
124 File: lispref.info, Node: Creating Strings, Next: Predicates for Characters, Prev: Predicates for Strings, Up: Strings and Characters
129 The following functions create strings, either from scratch, or by
130 putting strings together, or by taking them apart.
132 - Function: string &rest characters
133 This function returns a new string made up of CHARACTERS.
135 (string ?X ?E ?m ?a ?c ?s)
140 Analogous functions operating on other data types include `list',
141 `cons' (*note Building Lists::), `vector' (*note Vectors::) and
142 `bit-vector' (*note Bit Vectors::). This function has not been
143 available in XEmacs prior to 21.0 and FSF Emacs prior to 20.3.
145 - Function: make-string count character
146 This function returns a string made up of COUNT repetitions of
147 CHARACTER. If COUNT is negative, an error is signaled.
154 Other functions to compare with this one include `char-to-string'
155 (*note String Conversion::), `make-vector' (*note Vectors::), and
156 `make-list' (*note Building Lists::).
158 - Function: substring string start &optional end
159 This function returns a new string which consists of those
160 characters from STRING in the range from (and including) the
161 character at the index START up to (but excluding) the character
162 at the index END. The first character is at index zero.
164 (substring "abcdefg" 0 3)
167 Here the index for `a' is 0, the index for `b' is 1, and the index
168 for `c' is 2. Thus, three letters, `abc', are copied from the
169 string `"abcdefg"'. The index 3 marks the character position up
170 to which the substring is copied. The character whose index is 3
171 is actually the fourth character in the string.
173 A negative number counts from the end of the string, so that -1
174 signifies the index of the last character of the string. For
177 (substring "abcdefg" -3 -1)
180 In this example, the index for `e' is -3, the index for `f' is -2,
181 and the index for `g' is -1. Therefore, `e' and `f' are included,
184 When `nil' is used as an index, it stands for the length of the
187 (substring "abcdefg" -3 nil)
190 Omitting the argument END is equivalent to specifying `nil'. It
191 follows that `(substring STRING 0)' returns a copy of all of
194 (substring "abcdefg" 0)
197 But we recommend `copy-sequence' for this purpose (*note Sequence
200 If the characters copied from STRING have duplicable extents or
201 text properties, those are copied into the new string also. *Note
202 Duplicable Extents::.
204 A `wrong-type-argument' error is signaled if either START or END
205 is not an integer or `nil'. An `args-out-of-range' error is
206 signaled if START indicates a character following END, or if
207 either integer is out of range for STRING.
209 Contrast this function with `buffer-substring' (*note Buffer
210 Contents::), which returns a string containing a portion of the
211 text in the current buffer. The beginning of a string is at index
212 0, but the beginning of a buffer is at index 1.
214 - Function: concat &rest sequences
215 This function returns a new string consisting of the characters in
216 the arguments passed to it (along with their text properties, if
217 any). The arguments may be strings, lists of numbers, or vectors
218 of numbers; they are not themselves changed. If `concat' receives
219 no arguments, it returns an empty string.
221 (concat "abc" "-def")
223 (concat "abc" (list 120 (+ 256 121)) [122])
225 ;; `nil' is an empty sequence.
226 (concat "abc" nil "-def")
228 (concat "The " "quick brown " "fox.")
229 => "The quick brown fox."
233 The second example above shows how characters stored in strings are
234 taken modulo 256. In other words, each character in the string is
237 The `concat' function always constructs a new string that is not
238 `eq' to any existing string.
240 When an argument is an integer (not a sequence of integers), it is
241 converted to a string of digits making up the decimal printed
242 representation of the integer. *Don't use this feature; we plan
243 to eliminate it. If you already use this feature, change your
244 programs now!* The proper way to convert an integer to a decimal
245 number in this way is with `format' (*note Formatting Strings::) or
246 `number-to-string' (*note String Conversion::).
253 For information about other concatenation functions, see the
254 description of `mapconcat' in *Note Mapping Functions::, `vconcat'
255 in *Note Vectors::, `bvconcat' in *Note Bit Vectors::, and `append'
256 in *Note Building Lists::.
259 File: lispref.info, Node: Predicates for Characters, Next: Character Codes, Prev: Creating Strings, Up: Strings and Characters
261 The Predicates for Characters
262 =============================
264 - Function: characterp object
265 This function returns `t' if OBJECT is a character.
267 Some functions that work on integers (e.g. the comparison functions
268 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
269 accept characters and implicitly convert them into integers. In
270 general, functions that work on characters also accept char-ints
271 and implicitly convert them into characters. WARNING: Neither of
272 these behaviors is very desirable, and they are maintained for
273 backward compatibility with old E-Lisp programs that confounded
274 characters and integers willy-nilly. These behaviors may change
275 in the future; therefore, do not rely on them. Instead, convert
276 the characters explicitly using `char-int'.
278 - Function: integer-or-char-p object
279 This function returns `t' if OBJECT is an integer or character.
282 File: lispref.info, Node: Character Codes, Next: Text Comparison, Prev: Predicates for Characters, Up: Strings and Characters
287 - Function: char-int ch
288 This function converts a character into an equivalent integer.
289 The resulting integer will always be non-negative. The integers in
290 the range 0 - 255 map to characters as follows:
302 Right half of ISO-8859-1
304 If support for MULE does not exist, these are the only valid
305 character values. When MULE support exists, the values assigned to
306 other characters may vary depending on the particular version of
307 XEmacs, the order in which character sets were loaded, etc., and
308 you should not depend on them.
310 - Function: int-char integer
311 This function converts an integer into the equivalent character.
312 Not all integers correspond to valid characters; use `char-int-p'
313 to determine whether this is the case. If the integer cannot be
314 converted, `nil' is returned.
316 - Function: char-int-p object
317 This function returns `t' if OBJECT is an integer that can be
318 converted into a character.
320 - Function: char-or-char-int-p object
321 This function returns `t' if OBJECT is a character or an integer
322 that can be converted into one.
325 File: lispref.info, Node: Text Comparison, Next: String Conversion, Prev: Character Codes, Up: Strings and Characters
327 Comparison of Characters and Strings
328 ====================================
330 - Function: char-equal character1 character2
331 This function returns `t' if the arguments represent the same
332 character, `nil' otherwise. This function ignores differences in
333 case if `case-fold-search' is non-`nil'.
337 (let ((case-fold-search t))
340 (let ((case-fold-search nil))
344 - Function: char= character1 character2
345 This function returns `t' if the arguments represent the same
346 character, `nil' otherwise. Case is significant.
352 (let ((case-fold-search t))
355 (let ((case-fold-search nil))
359 - Function: string= string1 string2
360 This function returns `t' if the characters of the two strings
361 match exactly; case is significant.
363 (string= "abc" "abc")
365 (string= "abc" "ABC")
371 - Function: string-equal string1 string2
372 `string-equal' is another name for `string='.
374 - Function: string< string1 string2
375 This function compares two strings a character at a time. First it
376 scans both the strings at once to find the first pair of
377 corresponding characters that do not match. If the lesser
378 character of those two is the character from STRING1, then STRING1
379 is less, and this function returns `t'. If the lesser character
380 is the one from STRING2, then STRING1 is greater, and this
381 function returns `nil'. If the two strings match entirely, the
384 Pairs of characters are compared by their ASCII codes. Keep in
385 mind that lower case letters have higher numeric values in the
386 ASCII character set than their upper case counterparts; numbers and
387 many punctuation characters have a lower numeric value than upper
390 (string< "abc" "abd")
392 (string< "abd" "abc")
394 (string< "123" "abc")
397 When the strings have different lengths, and they match up to the
398 length of STRING1, then the result is `t'. If they match up to
399 the length of STRING2, the result is `nil'. A string of no
400 characters is less than any other string.
413 - Function: string-lessp string1 string2
414 `string-lessp' is another name for `string<'.
416 See also `compare-buffer-substrings' in *Note Comparing Text::, for
417 a way to compare text in buffers. The function `string-match', which
418 matches a regular expression against a string, can be used for a kind
419 of string comparison; see *Note Regexp Search::.
422 File: lispref.info, Node: String Conversion, Next: Modifying Strings, Prev: Text Comparison, Up: Strings and Characters
424 Conversion of Characters and Strings
425 ====================================
427 This section describes functions for conversions between characters,
428 strings and integers. `format' and `prin1-to-string' (*note Output
429 Functions::) can also convert Lisp objects into strings.
430 `read-from-string' (*note Input Functions::) can "convert" a string
431 representation of a Lisp object into an object.
433 *Note Documentation::, for functions that produce textual
434 descriptions of text characters and general input events
435 (`single-key-description' and `text-char-description'). These
436 functions are used primarily for making help messages.
438 - Function: char-to-string character
439 This function returns a new string with a length of one character.
440 The value of CHARACTER, modulo 256, is used to initialize the
441 element of the string.
443 This function is similar to `make-string' with an integer argument
444 of 1. (*Note Creating Strings::.) This conversion can also be
445 done with `format' using the `%c' format specification. (*Note
446 Formatting Strings::.)
450 (char-to-string (+ 256 ?x))
455 - Function: string-to-char string
456 This function returns the first character in STRING. If the
457 string is empty, the function returns 0. (Under XEmacs 19, the
458 value is also 0 when the first character of STRING is the null
459 character, ASCII code 0.)
461 (string-to-char "ABC")
462 => ?A ;; Under XEmacs 20.
463 => 65 ;; Under XEmacs 19.
464 (string-to-char "xyz")
465 => ?x ;; Under XEmacs 20.
466 => 120 ;; Under XEmacs 19.
469 (string-to-char "\000")
470 => ?\^ ;; Under XEmacs 20.
471 => 0 ;; Under XEmacs 20.
473 This function may be eliminated in the future if it does not seem
474 useful enough to retain.
476 - Function: number-to-string number
477 This function returns a string consisting of the printed
478 representation of NUMBER, which may be an integer or a floating
479 point number. The value starts with a sign if the argument is
482 (number-to-string 256)
484 (number-to-string -23)
486 (number-to-string -23.5)
489 `int-to-string' is a semi-obsolete alias for this function.
491 See also the function `format' in *Note Formatting Strings::.
493 - Function: string-to-number string &optional base
494 This function returns the numeric value of the characters in
495 STRING, read in BASE. It skips spaces and tabs at the beginning
496 of STRING, then reads as much of STRING as it can interpret as a
497 number. (On some systems it ignores other whitespace at the
498 beginning, not just spaces and tabs.) If the first character after
499 the ignored whitespace is not a digit or a minus sign, this
502 If BASE is not specified, it defaults to ten. With BASE other
503 than ten, only integers can be read.
505 (string-to-number "256")
507 (string-to-number "25 is a perfect square.")
509 (string-to-number "X256")
511 (string-to-number "-4.5")
513 (string-to-number "ffff" 16)
516 `string-to-int' is an obsolete alias for this function.
519 File: lispref.info, Node: Modifying Strings, Next: String Properties, Prev: String Conversion, Up: Strings and Characters
524 You can modify a string using the general array-modifying primitives.
525 *Note Arrays::. The function `aset' modifies a single character; the
526 function `fillarray' sets all characters in the string to a specified
529 Each string has a tick counter that starts out at zero (when the
530 string is created) and is incremented each time a change is made to that
533 - Function: string-modified-tick string
534 This function returns the tick counter for `string'.
537 File: lispref.info, Node: String Properties, Next: Formatting Strings, Prev: Modifying Strings, Up: Strings and Characters
542 Just as with symbols, extents, faces, and glyphs, you can attach
543 additional information to strings in the form of "string properties".
544 These differ from text properties, which are logically attached to
545 particular characters in the string.
547 To attach a property to a string, use `put'. To retrieve a property
548 from a string, use `get'. You can also use `remprop' to remove a
549 property from a string and `object-plist' to retrieve a list of all the
550 properties in a string.
553 File: lispref.info, Node: Formatting Strings, Next: Character Case, Prev: String Properties, Up: Strings and Characters
558 "Formatting" means constructing a string by substitution of computed
559 values at various places in a constant string. This string controls
560 how the other values are printed as well as where they appear; it is
561 called a "format string".
563 Formatting is often useful for computing messages to be displayed.
564 In fact, the functions `message' and `error' provide the same
565 formatting feature described here; they differ from `format' only in
566 how they use the result of formatting.
568 - Function: format string &rest objects
569 This function returns a new string that is made by copying STRING
570 and then replacing any format specification in the copy with
571 encodings of the corresponding OBJECTS. The arguments OBJECTS are
572 the computed values to be formatted.
574 A format specification is a sequence of characters beginning with a
575 `%'. Thus, if there is a `%d' in STRING, the `format' function
576 replaces it with the printed representation of one of the values to be
577 formatted (one of the arguments OBJECTS). For example:
579 (format "The value of fill-column is %d." fill-column)
580 => "The value of fill-column is 72."
582 If STRING contains more than one format specification, the format
583 specifications correspond with successive values from OBJECTS. Thus,
584 the first format specification in STRING uses the first such value, the
585 second format specification uses the second such value, and so on. Any
586 extra format specifications (those for which there are no corresponding
587 values) cause unpredictable behavior. Any extra values to be formatted
590 Certain format specifications require values of particular types.
591 However, no error is signaled if the value actually supplied fails to
592 have the expected type. Instead, the output is likely to be
595 Here is a table of valid format specifications:
598 Replace the specification with the printed representation of the
599 object, made without quoting. Thus, strings are represented by
600 their contents alone, with no `"' characters, and symbols appear
601 without `\' characters. This is equivalent to printing the object
604 If there is no corresponding object, the empty string is used.
607 Replace the specification with the printed representation of the
608 object, made with quoting. Thus, strings are enclosed in `"'
609 characters, and `\' characters appear where necessary before
610 special characters. This is equivalent to printing the object
613 If there is no corresponding object, the empty string is used.
616 Replace the specification with the base-eight representation of an
621 Replace the specification with the base-ten representation of an
625 Replace the specification with the base-sixteen representation of
626 an integer, using lowercase letters.
629 Replace the specification with the base-sixteen representation of
630 an integer, using uppercase letters.
633 Replace the specification with the character which is the value
637 Replace the specification with the exponential notation for a
638 floating point number (e.g. `7.85200e+03').
641 Replace the specification with the decimal-point notation for a
642 floating point number.
645 Replace the specification with notation for a floating point
646 number, using a "pretty format". Either exponential notation or
647 decimal-point notation will be used (usually whichever is
648 shorter), and trailing zeroes are removed from the fractional part.
651 A single `%' is placed in the string. This format specification is
652 unusual in that it does not use a value. For example, `(format "%%
653 %d" 30)' returns `"% 30"'.
655 Any other format character results in an `Invalid format operation'
658 Here are several examples:
660 (format "The name of this buffer is %s." (buffer-name))
661 => "The name of this buffer is strings.texi."
663 (format "The buffer object prints as %s." (current-buffer))
664 => "The buffer object prints as #<buffer strings.texi>."
666 (format "The octal value of %d is %o,
667 and the hex value is %x." 18 18 18)
668 => "The octal value of 18 is 22,
669 and the hex value is 12."
671 There are many additional flags and specifications that can occur
672 between the `%' and the format character, in the following order:
674 1. An optional repositioning specification, which is a positive
675 integer followed by a `$'.
677 2. Zero or more of the optional flag characters `-', `+', ` ', `0',
680 3. An asterisk (`*', meaning that the field width is now assumed to
681 have been specified as an argument.
683 4. An optional minimum field width.
685 5. An optional precision, preceded by a `.' character.
687 A "repositioning" specification changes which argument to `format'
688 is used by the current and all following format specifications.
689 Normally the first specification uses the first argument, the second
690 specification uses the second argument, etc. Using a repositioning
691 specification, you can change this. By placing a number N followed by
692 a `$' between the `%' and the format character, you cause the
693 specification to use the Nth argument. The next specification will use
694 the N+1'th argument, etc.
698 (format "Can't find file `%s' in directory `%s'."
699 "ignatius.c" "loyola/")
700 => "Can't find file `ignatius.c' in directory `loyola/'."
702 (format "In directory `%2$s', the file `%1$s' was not found."
703 "ignatius.c" "loyola/")
704 => "In directory `loyola/', the file `ignatius.c' was not found."
707 "The numbers %d and %d are %1$x and %x in hex and %1$o and %o in octal."
709 => "The numbers 37 and 12 are 25 and c in hex and 45 and 14 in octal."
711 As you can see, this lets you reprocess arguments more than once or
712 reword a format specification (thereby moving the arguments around)
713 without having to actually reorder the arguments. This is especially
714 useful in translating messages from one language to another: Different
715 languages use different word orders, and this sometimes entails changing
716 the order of the arguments. By using repositioning specifications,
717 this can be accomplished without having to embed knowledge of particular
718 languages into the location in the program's code where the message is
721 All the specification characters allow an optional numeric prefix
722 between the `%' and the character, and following any repositioning
723 specification or flag. The optional numeric prefix defines the minimum
724 width for the object. If the printed representation of the object
725 contains fewer characters than this, then it is padded. The padding is
726 normally on the left, but will be on the right if the `-' flag
727 character is given. The padding character is normally a space, but if
728 the `0' flag character is given, zeros are used for padding.
730 (format "%06d is padded on the left with zeros" 123)
731 => "000123 is padded on the left with zeros"
733 (format "%-6d is padded on the right" 123)
734 => "123 is padded on the right"
736 `format' never truncates an object's printed representation, no
737 matter what width you specify. Thus, you can use a numeric prefix to
738 specify a minimum spacing between columns with no risk of losing
741 In the following three examples, `%7s' specifies a minimum width of
742 7. In the first case, the string inserted in place of `%7s' has only 3
743 letters, so 4 blank spaces are inserted for padding. In the second
744 case, the string `"specification"' is 13 letters wide but is not
745 truncated. In the third case, the padding is on the right.
747 (format "The word `%7s' actually has %d letters in it."
748 "foo" (length "foo"))
749 => "The word ` foo' actually has 3 letters in it."
751 (format "The word `%7s' actually has %d letters in it."
752 "specification" (length "specification"))
753 => "The word `specification' actually has 13 letters in it."
755 (format "The word `%-7s' actually has %d letters in it."
756 "foo" (length "foo"))
757 => "The word `foo ' actually has 3 letters in it."
759 After any minimum field width, a precision may be specified by
760 preceding it with a `.' character. The precision specifies the minimum
761 number of digits to appear in `%d', `%i', `%o', `%x', and `%X'
762 conversions (the number is padded on the left with zeroes as
763 necessary); the number of digits printed after the decimal point for
764 `%f', `%e', and `%E' conversions; the number of significant digits
765 printed in `%g' and `%G' conversions; and the maximum number of
766 non-padding characters printed in `%s' and `%S' conversions. The
767 default precision for floating-point conversions is six.
769 The other flag characters have the following meanings:
771 * The ` ' flag means prefix non-negative numbers with a space.
773 * The `+' flag means prefix non-negative numbers with a plus sign.
775 * The `#' flag means print numbers in an alternate, more verbose
776 format: octal numbers begin with zero; hex numbers begin with a
777 `0x' or `0X'; a decimal point is printed in `%f', `%e', and `%E'
778 conversions even if no numbers are printed after it; and trailing
779 zeroes are not omitted in `%g' and `%G' conversions.
782 File: lispref.info, Node: Character Case, Next: Case Tables, Prev: Formatting Strings, Up: Strings and Characters
787 The character case functions change the case of single characters or
788 of the contents of strings. The functions convert only alphabetic
789 characters (the letters `A' through `Z' and `a' through `z'); other
790 characters are not altered. The functions do not modify the strings
791 that are passed to them as arguments.
793 The examples below use the characters `X' and `x' which have ASCII
794 codes 88 and 120 respectively.
796 - Function: downcase string-or-char
797 This function converts a character or a string to lower case.
799 When the argument to `downcase' is a string, the function creates
800 and returns a new string in which each letter in the argument that
801 is upper case is converted to lower case. When the argument to
802 `downcase' is a character, `downcase' returns the corresponding
803 lower case character. (This value is actually an integer under
804 XEmacs 19.) If the original character is lower case, or is not a
805 letter, then the value equals the original character.
807 (downcase "The cat in the hat")
808 => "the cat in the hat"
811 => ?x ;; Under XEmacs 20.
812 => 120 ;; Under XEmacs 19.
814 - Function: upcase string-or-char
815 This function converts a character or a string to upper case.
817 When the argument to `upcase' is a string, the function creates
818 and returns a new string in which each letter in the argument that
819 is lower case is converted to upper case.
821 When the argument to `upcase' is a character, `upcase' returns the
822 corresponding upper case character. (This value is actually an
823 integer under XEmacs 19.) If the original character is upper
824 case, or is not a letter, then the value equals the original
827 (upcase "The cat in the hat")
828 => "THE CAT IN THE HAT"
831 => ?X ;; Under XEmacs 20.
832 => 88 ;; Under XEmacs 19.
834 - Function: capitalize string-or-char
835 This function capitalizes strings or characters. If
836 STRING-OR-CHAR is a string, the function creates and returns a new
837 string, whose contents are a copy of STRING-OR-CHAR in which each
838 word has been capitalized. This means that the first character of
839 each word is converted to upper case, and the rest are converted
842 The definition of a word is any sequence of consecutive characters
843 that are assigned to the word constituent syntax class in the
844 current syntax table (*note Syntax Class Table::).
846 When the argument to `capitalize' is a character, `capitalize' has
847 the same result as `upcase'.
849 (capitalize "The cat in the hat")
850 => "The Cat In The Hat"
852 (capitalize "THE 77TH-HATTED CAT")
853 => "The 77th-Hatted Cat"
856 => ?X ;; Under XEmacs 20.
857 => 88 ;; Under XEmacs 19.
860 File: lispref.info, Node: Case Tables, Next: Char Tables, Prev: Character Case, Up: Strings and Characters
865 You can customize case conversion by installing a special "case
866 table". A case table specifies the mapping between upper case and lower
867 case letters. It affects both the string and character case conversion
868 functions (see the previous section) and those that apply to text in the
869 buffer (*note Case Changes::). You need a case table if you are using a
870 language which has letters other than the standard ASCII letters.
872 A case table is a list of this form:
874 (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
876 where each element is either `nil' or a string of length 256. The
877 element DOWNCASE says how to map each character to its lower-case
878 equivalent. The element UPCASE maps each character to its upper-case
879 equivalent. If lower and upper case characters are in one-to-one
880 correspondence, use `nil' for UPCASE; then XEmacs deduces the upcase
883 For some languages, upper and lower case letters are not in
884 one-to-one correspondence. There may be two different lower case
885 letters with the same upper case equivalent. In these cases, you need
886 to specify the maps for both directions.
888 The element CANONICALIZE maps each character to a canonical
889 equivalent; any two characters that are related by case-conversion have
890 the same canonical equivalent character.
892 The element EQUIVALENCES is a map that cyclicly permutes each
893 equivalence class (of characters with the same canonical equivalent).
894 (For ordinary ASCII, this would map `a' into `A' and `A' into `a', and
895 likewise for each set of equivalent characters.)
897 When you construct a case table, you can provide `nil' for
898 CANONICALIZE; then Emacs fills in this string from UPCASE and DOWNCASE.
899 You can also provide `nil' for EQUIVALENCES; then Emacs fills in this
900 string from CANONICALIZE. In a case table that is actually in use,
901 those components are non-`nil'. Do not try to specify EQUIVALENCES
902 without also specifying CANONICALIZE.
904 Each buffer has a case table. XEmacs also has a "standard case
905 table" which is copied into each buffer when you create the buffer.
906 Changing the standard case table doesn't affect any existing buffers.
908 Here are the functions for working with case tables:
910 - Function: case-table-p object
911 This predicate returns non-`nil' if OBJECT is a valid case table.
913 - Function: set-standard-case-table table
914 This function makes TABLE the standard case table, so that it will
915 apply to any buffers created subsequently.
917 - Function: standard-case-table
918 This returns the standard case table.
920 - Function: current-case-table
921 This function returns the current buffer's case table.
923 - Function: set-case-table table
924 This sets the current buffer's case table to TABLE.
926 The following three functions are convenient subroutines for packages
927 that define non-ASCII character sets. They modify a string
928 DOWNCASE-TABLE provided as an argument; this should be a string to be
929 used as the DOWNCASE part of a case table. They also modify the
930 standard syntax table. *Note Syntax Tables::.
932 - Function: set-case-syntax-pair uc lc downcase-table
933 This function specifies a pair of corresponding letters, one upper
934 case and one lower case.
936 - Function: set-case-syntax-delims l r downcase-table
937 This function makes characters L and R a matching pair of
938 case-invariant delimiters.
940 - Function: set-case-syntax char syntax downcase-table
941 This function makes CHAR case-invariant, with syntax SYNTAX.
943 - Command: describe-buffer-case-table
944 This command displays a description of the contents of the current
947 You can load the library `iso-syntax' to set up the standard syntax
948 table and define a case table for the 8-bit ISO Latin 1 character set.
951 File: lispref.info, Node: Char Tables, Prev: Case Tables, Up: Strings and Characters
956 A char table is a table that maps characters (or ranges of
957 characters) to values. Char tables are specialized for characters,
958 only allowing particular sorts of ranges to be assigned values.
959 Although this loses in generality, it makes for extremely fast
960 (constant-time) lookups, and thus is feasible for applications that do
961 an extremely large number of lookups (e.g. scanning a buffer for a
962 character in a particular syntax, where a lookup in the syntax table
963 must occur once per character).
965 Note that char tables as a primitive type, and all of the functions
966 in this section, exist only in XEmacs 20. In XEmacs 19, char tables are
967 generally implemented using a vector of 256 elements.
969 When MULE support exists, the types of ranges that can be assigned
976 * a single row in a two-octet charset
980 When MULE support is not present, the types of ranges that can be
987 - Function: char-table-p object
988 This function returns non-`nil' if OBJECT is a char table.
992 * Char Table Types:: Char tables have different uses.
993 * Working With Char Tables:: Creating and working with char tables.
996 File: lispref.info, Node: Char Table Types, Next: Working With Char Tables, Up: Char Tables
1001 Each char table type is used for a different purpose and allows
1002 different sorts of values. The different char table types are
1005 Used for category tables, which specify the regexp categories that
1006 a character is in. The valid values are `nil' or a bit vector of
1007 95 elements. Higher-level Lisp functions are provided for working
1008 with category tables. Currently categories and category tables
1009 only exist when MULE support is present.
1012 A generalized char table, for mapping from one character to
1013 another. Used for case tables, syntax matching tables,
1014 `keyboard-translate-table', etc. The valid values are characters.
1017 An even more generalized char table, for mapping from a character
1021 Used for display tables, which specify how a particular character
1022 is to appear when displayed. #### Not yet implemented.
1025 Used for syntax tables, which specify the syntax of a particular
1026 character. Higher-level Lisp functions are provided for working
1027 with syntax tables. The valid values are integers.
1029 - Function: char-table-type table
1030 This function returns the type of char table TABLE.
1032 - Function: char-table-type-list
1033 This function returns a list of the recognized char table types.
1035 - Function: valid-char-table-type-p type
1036 This function returns `t' if TYPE if a recognized char table type.
1039 File: lispref.info, Node: Working With Char Tables, Prev: Char Table Types, Up: Char Tables
1041 Working With Char Tables
1042 ------------------------
1044 - Function: make-char-table type
1045 This function makes a new, empty char table of type TYPE. TYPE
1046 should be a symbol, one of `char', `category', `display',
1047 `generic', or `syntax'.
1049 - Function: put-char-table range val table
1050 This function sets the value for chars in RANGE to be VAL in TABLE.
1052 RANGE specifies one or more characters to be affected and should be
1053 one of the following:
1055 * `t' (all characters are affected)
1057 * A charset (only allowed when MULE support is present)
1059 * A vector of two elements: a two-octet charset and a row number
1060 (only allowed when MULE support is present)
1062 * A single character
1064 VAL must be a value appropriate for the type of TABLE.
1066 - Function: get-char-table ch table
1067 This function finds the value for char CH in TABLE.
1069 - Function: get-range-char-table range table &optional multi
1070 This function finds the value for a range in TABLE. If there is
1071 more than one value, MULTI is returned (defaults to `nil').
1073 - Function: reset-char-table table
1074 This function resets a char table to its default state.
1076 - Function: map-char-table function table &optional range
1077 This function maps FUNCTION over entries in TABLE, calling it with
1078 two args, each key and value in the table.
1080 RANGE specifies a subrange to map over and is in the same format
1081 as the RANGE argument to `put-range-table'. If omitted or `t', it
1082 defaults to the entire table.
1084 - Function: valid-char-table-value-p value char-table-type
1085 This function returns non-`nil' if VALUE is a valid value for
1088 - Function: check-valid-char-table-value value char-table-type
1089 This function signals an error if VALUE is not a valid value for
1093 File: lispref.info, Node: Lists, Next: Sequences Arrays Vectors, Prev: Strings and Characters, Up: Top
1098 A "list" represents a sequence of zero or more elements (which may
1099 be any Lisp objects). The important difference between lists and
1100 vectors is that two or more lists can share part of their structure; in
1101 addition, you can insert or delete elements in a list without copying
1106 * Cons Cells:: How lists are made out of cons cells.
1107 * Lists as Boxes:: Graphical notation to explain lists.
1108 * List-related Predicates:: Is this object a list? Comparing two lists.
1109 * List Elements:: Extracting the pieces of a list.
1110 * Building Lists:: Creating list structure.
1111 * Modifying Lists:: Storing new pieces into an existing list.
1112 * Sets And Lists:: A list can represent a finite mathematical set.
1113 * Association Lists:: A list can represent a finite relation or mapping.
1114 * Property Lists:: A different way to represent a finite mapping.
1115 * Weak Lists:: A list with special garbage-collection behavior.
1118 File: lispref.info, Node: Cons Cells, Next: Lists as Boxes, Up: Lists
1120 Lists and Cons Cells
1121 ====================
1123 Lists in Lisp are not a primitive data type; they are built up from
1124 "cons cells". A cons cell is a data object that represents an ordered
1125 pair. It records two Lisp objects, one labeled as the CAR, and the
1126 other labeled as the CDR. These names are traditional; see *Note Cons
1127 Cell Type::. CDR is pronounced "could-er."
1129 A list is a series of cons cells chained together, one cons cell per
1130 element of the list. By convention, the CARs of the cons cells are the
1131 elements of the list, and the CDRs are used to chain the list: the CDR
1132 of each cons cell is the following cons cell. The CDR of the last cons
1133 cell is `nil'. This asymmetry between the CAR and the CDR is entirely
1134 a matter of convention; at the level of cons cells, the CAR and CDR
1135 slots have the same characteristics.
1137 Because most cons cells are used as part of lists, the phrase "list
1138 structure" has come to mean any structure made out of cons cells.
1140 The symbol `nil' is considered a list as well as a symbol; it is the
1141 list with no elements. For convenience, the symbol `nil' is considered
1142 to have `nil' as its CDR (and also as its CAR).
1144 The CDR of any nonempty list L is a list containing all the elements
1145 of L except the first.
1148 File: lispref.info, Node: Lists as Boxes, Next: List-related Predicates, Prev: Cons Cells, Up: Lists
1150 Lists as Linked Pairs of Boxes
1151 ==============================
1153 A cons cell can be illustrated as a pair of boxes. The first box
1154 represents the CAR and the second box represents the CDR. Here is an
1155 illustration of the two-element list, `(tulip lily)', made from two
1158 --------------- ---------------
1159 | car | cdr | | car | cdr |
1160 | tulip | o---------->| lily | nil |
1162 --------------- ---------------
1164 Each pair of boxes represents a cons cell. Each box "refers to",
1165 "points to" or "contains" a Lisp object. (These terms are synonymous.)
1166 The first box, which is the CAR of the first cons cell, contains the
1167 symbol `tulip'. The arrow from the CDR of the first cons cell to the
1168 second cons cell indicates that the CDR of the first cons cell points
1169 to the second cons cell.
1171 The same list can be illustrated in a different sort of box notation
1175 |___|___|--> |___|___|--> nil
1180 Here is a more complex illustration, showing the three-element list,
1181 `((pine needles) oak maple)', the first element of which is a
1184 ___ ___ ___ ___ ___ ___
1185 |___|___|--> |___|___|--> |___|___|--> nil
1191 --> |___|___|--> |___|___|--> nil
1194 --> pine --> needles
1196 The same list represented in the first box notation looks like this:
1198 -------------- -------------- --------------
1199 | car | cdr | | car | cdr | | car | cdr |
1200 | o | o------->| oak | o------->| maple | nil |
1202 -- | --------- -------------- --------------
1205 | -------------- ----------------
1206 | | car | cdr | | car | cdr |
1207 ------>| pine | o------->| needles | nil |
1209 -------------- ----------------
1211 *Note Cons Cell Type::, for the read and print syntax of cons cells
1212 and lists, and for more "box and arrow" illustrations of lists.
1215 File: lispref.info, Node: List-related Predicates, Next: List Elements, Prev: Lists as Boxes, Up: Lists
1220 The following predicates test whether a Lisp object is an atom, is a
1221 cons cell or is a list, or whether it is the distinguished object
1222 `nil'. (Many of these predicates can be defined in terms of the
1223 others, but they are used so often that it is worth having all of them.)
1225 - Function: consp object
1226 This function returns `t' if OBJECT is a cons cell, `nil'
1227 otherwise. `nil' is not a cons cell, although it _is_ a list.
1229 - Function: atom object
1230 This function returns `t' if OBJECT is an atom, `nil' otherwise.
1231 All objects except cons cells are atoms. The symbol `nil' is an
1232 atom and is also a list; it is the only Lisp object that is both.
1234 (atom OBJECT) == (not (consp OBJECT))
1236 - Function: listp object
1237 This function returns `t' if OBJECT is a cons cell or `nil'.
1238 Otherwise, it returns `nil'.
1245 - Function: nlistp object
1246 This function is the opposite of `listp': it returns `t' if OBJECT
1247 is not a list. Otherwise, it returns `nil'.
1249 (listp OBJECT) == (not (nlistp OBJECT))
1251 - Function: null object
1252 This function returns `t' if OBJECT is `nil', and returns `nil'
1253 otherwise. This function is identical to `not', but as a matter
1254 of clarity we use `null' when OBJECT is considered a list and
1255 `not' when it is considered a truth value (see `not' in *Note
1256 Combining Conditions::).