This commit was generated by cvs2svn to compensate for changes in r6453,
[chise/xemacs-chise.git.1] / info / lispref.info-5
1 This is Info file ../../info/lispref.info, produced by Makeinfo version
2 1.68 from the input file lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
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
20
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.
24
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.
28
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.
33
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.
38
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.
45
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.
51
52 \1f
53 File: lispref.info,  Node: String Basics,  Next: Predicates for Strings,  Up: Strings and Characters
54
55 String and Character Basics
56 ===========================
57
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::.
63
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
69 element of a string.
70
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::.).
75
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
78 length.
79
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
84 characters.
85
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.
91
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
96 Extents::.
97
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.
101
102 \1f
103 File: lispref.info,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: String Basics,  Up: Strings and Characters
104
105 The Predicates for Strings
106 ==========================
107
108    For more information about general sequence and array predicates,
109 see *Note Sequences Arrays Vectors::, and *Note Arrays::.
110
111  - Function: stringp OBJECT
112      This function returns `t' if OBJECT is a string, `nil' otherwise.
113
114  - Function: char-or-string-p OBJECT
115      This function returns `t' if OBJECT is a string or a character,
116      `nil' otherwise.
117
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
121      on.
122
123 \1f
124 File: lispref.info,  Node: Creating Strings,  Next: Predicates for Characters,  Prev: Predicates for Strings,  Up: Strings and Characters
125
126 Creating Strings
127 ================
128
129    The following functions create strings, either from scratch, or by
130 putting strings together, or by taking them apart.
131
132  - Function: string &rest CHARACTERS
133      This function returns a new string made up of CHARACTERS.
134
135           (string ?X ?E ?m ?a ?c ?s)
136                => "XEmacs"
137           (string)
138                => ""
139
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.
144
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.
148
149           (make-string 5 ?x)
150                => "xxxxx"
151           (make-string 0 ?x)
152                => ""
153
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::.).
157
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.
163
164           (substring "abcdefg" 0 3)
165                => "abc"
166
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.
172
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
175      example:
176
177           (substring "abcdefg" -3 -1)
178                => "ef"
179
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,
182      and `g' is excluded.
183
184      When `nil' is used as an index, it stands for the length of the
185      string.  Thus,
186
187           (substring "abcdefg" -3 nil)
188                => "efg"
189
190      Omitting the argument END is equivalent to specifying `nil'.  It
191      follows that `(substring STRING 0)' returns a copy of all of
192      STRING.
193
194           (substring "abcdefg" 0)
195                => "abcdefg"
196
197      But we recommend `copy-sequence' for this purpose (*note Sequence
198      Functions::.).
199
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::.
203
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.
208
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.
213
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.
220
221           (concat "abc" "-def")
222                => "abc-def"
223           (concat "abc" (list 120 (+ 256 121)) [122])
224                => "abcxyz"
225           ;; `nil' is an empty sequence.
226           (concat "abc" nil "-def")
227                => "abc-def"
228           (concat "The " "quick brown " "fox.")
229                => "The quick brown fox."
230           (concat)
231                => ""
232
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
235      stored in one byte.
236
237      The `concat' function always constructs a new string that is not
238      `eq' to any existing string.
239
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::.)
246      or `number-to-string' (*note String Conversion::.).
247
248           (concat 137)
249                => "137"
250           (concat 54 321)
251                => "54321"
252
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::.
257
258 \1f
259 File: lispref.info,  Node: Predicates for Characters,  Next: Character Codes,  Prev: Creating Strings,  Up: Strings and Characters
260
261 The Predicates for Characters
262 =============================
263
264  - Function: characterp OBJECT
265      This function returns `t' if OBJECT is a character.
266
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'.
277
278  - Function: integer-or-char-p OBJECT
279      This function returns `t' if OBJECT is an integer or character.
280
281 \1f
282 File: lispref.info,  Node: Character Codes,  Next: Text Comparison,  Prev: Predicates for Characters,  Up: Strings and Characters
283
284 Character Codes
285 ===============
286
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:
291
292     0 - 31
293           Control set 0
294
295     32 - 127
296           ASCII
297
298     128 - 159
299           Control set 1
300
301     160 - 255
302           Right half of ISO-8859-1
303
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.
309
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.
315
316  - Function: char-int-p OBJECT
317      This function returns `t' if OBJECT is an integer that can be
318      converted into a character.
319
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.
323
324 \1f
325 File: lispref.info,  Node: Text Comparison,  Next: String Conversion,  Prev: Character Codes,  Up: Strings and Characters
326
327 Comparison of Characters and Strings
328 ====================================
329
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'.
334
335           (char-equal ?x ?x)
336                => t
337           (let ((case-fold-search t))
338             (char-equal ?x ?X))
339                => t
340           (let ((case-fold-search nil))
341             (char-equal ?x ?X))
342                => nil
343
344  - Function: char= CHARACTER1 CHARACTER2
345      This function returns `t' if the arguments represent the same
346      character, `nil' otherwise.  Case is significant.
347
348           (char= ?x ?x)
349                => t
350           (char= ?x ?X)
351                => nil
352           (let ((case-fold-search t))
353             (char-equal ?x ?X))
354                => nil
355           (let ((case-fold-search nil))
356             (char-equal ?x ?X))
357                => nil
358
359  - Function: string= STRING1 STRING2
360      This function returns `t' if the characters of the two strings
361      match exactly; case is significant.
362
363           (string= "abc" "abc")
364                => t
365           (string= "abc" "ABC")
366                => nil
367           (string= "ab" "ABC")
368                => nil
369
370
371  - Function: string-equal STRING1 STRING2
372      `string-equal' is another name for `string='.
373
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
382      value is `nil'.
383
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
388      case letters.
389
390           (string< "abc" "abd")
391                => t
392           (string< "abd" "abc")
393                => nil
394           (string< "123" "abc")
395                => t
396
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.
401
402           (string< "" "abc")
403                => t
404           (string< "ab" "abc")
405                => t
406           (string< "abc" "")
407                => nil
408           (string< "abc" "ab")
409                => nil
410           (string< "" "")
411                => nil
412
413  - Function: string-lessp STRING1 STRING2
414      `string-lessp' is another name for `string<'.
415
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::.
420
421 \1f
422 File: lispref.info,  Node: String Conversion,  Next: Modifying Strings,  Prev: Text Comparison,  Up: Strings and Characters
423
424 Conversion of Characters and Strings
425 ====================================
426
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.
432
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.
437
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.
442
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::.)
447
448           (char-to-string ?x)
449                => "x"
450           (char-to-string (+ 256 ?x))
451                => "x"
452           (make-string 1 ?x)
453                => "x"
454
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.)
460
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.
467           (string-to-char "")
468                => 0
469           (string-to-char "\000")
470                => ?\^ ;; Under XEmacs 20.
471                => 0    ;; Under XEmacs 20.
472
473      This function may be eliminated in the future if it does not seem
474      useful enough to retain.
475
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
480      negative.
481
482           (number-to-string 256)
483                => "256"
484           (number-to-string -23)
485                => "-23"
486           (number-to-string -23.5)
487                => "-23.5"
488
489      `int-to-string' is a semi-obsolete alias for this function.
490
491      See also the function `format' in *Note Formatting Strings::.
492
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
500      function returns 0.
501
502      If BASE is not specified, it defaults to ten.  With BASE other
503      than ten, only integers can be read.
504
505           (string-to-number "256")
506                => 256
507           (string-to-number "25 is a perfect square.")
508                => 25
509           (string-to-number "X256")
510                => 0
511           (string-to-number "-4.5")
512                => -4.5
513           (string-to-number "ffff" 16)
514                => 65535
515
516      `string-to-int' is an obsolete alias for this function.
517
518 \1f
519 File: lispref.info,  Node: Modifying Strings,  Next: String Properties,  Prev: String Conversion,  Up: Strings and Characters
520
521 Modifying Strings
522 =================
523
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
527 character.
528
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
531 string.
532
533  - Function: string-modified-tick STRING
534      This function returns the tick counter for `string'.
535
536 \1f
537 File: lispref.info,  Node: String Properties,  Next: Formatting Strings,  Prev: Modifying Strings,  Up: Strings and Characters
538
539 String Properties
540 =================
541
542    Similar to 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.
546
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-props' to retrieve a list of all the
550 properties in a string.
551
552 \1f
553 File: lispref.info,  Node: Formatting Strings,  Next: Character Case,  Prev: String Properties,  Up: Strings and Characters
554
555 Formatting Strings
556 ==================
557
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".
562
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.
567
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.
573
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:
578
579      (format "The value of fill-column is %d." fill-column)
580           => "The value of fill-column is 72."
581
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
588 are ignored.
589
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
593 meaningless.
594
595    Here is a table of valid format specifications:
596
597 `%s'
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
602      with `princ'.
603
604      If there is no corresponding object, the empty string is used.
605
606 `%S'
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
611      with `prin1'.
612
613      If there is no corresponding object, the empty string is used.
614
615 `%o'
616      Replace the specification with the base-eight representation of an
617      integer.
618
619 `%d'
620 `%i'
621      Replace the specification with the base-ten representation of an
622      integer.
623
624 `%x'
625      Replace the specification with the base-sixteen representation of
626      an integer, using lowercase letters.
627
628 `%X'
629      Replace the specification with the base-sixteen representation of
630      an integer, using uppercase letters.
631
632 `%c'
633      Replace the specification with the character which is the value
634      given.
635
636 `%e'
637      Replace the specification with the exponential notation for a
638      floating point number (e.g. `7.85200e+03').
639
640 `%f'
641      Replace the specification with the decimal-point notation for a
642      floating point number.
643
644 `%g'
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.
649
650 `%%'
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"'.
654
655    Any other format character results in an `Invalid format operation'
656 error.
657
658    Here are several examples:
659
660      (format "The name of this buffer is %s." (buffer-name))
661           => "The name of this buffer is strings.texi."
662      
663      (format "The buffer object prints as %s." (current-buffer))
664           => "The buffer object prints as #<buffer strings.texi>."
665      
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."
670
671    There are many additional flags and specifications that can occur
672 between the `%' and the format character, in the following order:
673
674   1. An optional repositioning specification, which is a positive
675      integer followed by a `$'.
676
677   2. Zero or more of the optional flag characters `-', `+', ` ', `0',
678      and `#'.
679
680   3. An asterisk (`*', meaning that the field width is now assumed to
681      have been specified as an argument.
682
683   4. An optional minimum field width.
684
685   5. An optional precision, preceded by a `.' character.
686
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.
695
696    For example:
697
698      (format "Can't find file `%s' in directory `%s'."
699              "ignatius.c" "loyola/")
700           => "Can't find file `ignatius.c' in directory `loyola/'."
701      
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."
705      
706      (format
707          "The numbers %d and %d are %1$x and %x in hex and %1$o and %o in octal."
708          37 12)
709      => "The numbers 37 and 12 are 25 and c in hex and 45 and 14 in octal."
710
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
719 displayed.
720
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.
729
730      (format "%06d is padded on the left with zeros" 123)
731           => "000123 is padded on the left with zeros"
732      
733      (format "%-6d is padded on the right" 123)
734           => "123    is padded on the right"
735
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
739 information.
740
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.
746
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."
750
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."
754
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."
758
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.
768
769    The other flag characters have the following meanings:
770
771    * The ` ' flag means prefix non-negative numbers with a space.
772
773    * The `+' flag means prefix non-negative numbers with a plus sign.
774
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.
780
781 \1f
782 File: lispref.info,  Node: Character Case,  Next: Case Tables,  Prev: Formatting Strings,  Up: Strings and Characters
783
784 Character Case
785 ==============
786
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.
792
793    The examples below use the characters `X' and `x' which have ASCII
794 codes 88 and 120 respectively.
795
796  - Function: downcase STRING-OR-CHAR
797      This function converts a character or a string to lower case.
798
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.
806
807           (downcase "The cat in the hat")
808                => "the cat in the hat"
809           
810           (downcase ?X)
811                => ?x   ;; Under XEmacs 20.
812                => 120  ;; Under XEmacs 19.
813
814  - Function: upcase STRING-OR-CHAR
815      This function converts a character or a string to upper case.
816
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.
820
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
825      character.
826
827           (upcase "The cat in the hat")
828                => "THE CAT IN THE HAT"
829           
830           (upcase ?x)
831                => ?X   ;; Under XEmacs 20.
832                => 88   ;; Under XEmacs 19.
833
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
840      to lower case.
841
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::.).
845
846      When the argument to `capitalize' is a character, `capitalize' has
847      the same result as `upcase'.
848
849           (capitalize "The cat in the hat")
850                => "The Cat In The Hat"
851           
852           (capitalize "THE 77TH-HATTED CAT")
853                => "The 77th-Hatted Cat"
854           
855           (capitalize ?x)
856                => ?X   ;; Under XEmacs 20.
857                => 88   ;; Under XEmacs 19.
858
859 \1f
860 File: lispref.info,  Node: Case Tables,  Next: Char Tables,  Prev: Character Case,  Up: Strings and Characters
861
862 The Case Table
863 ==============
864
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
870 a language which has letters other than the standard ASCII letters.
871
872    A case table is a list of this form:
873
874      (DOWNCASE UPCASE CANONICALIZE EQUIVALENCES)
875
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
881 table from DOWNCASE.
882
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.
887
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.
891
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.)
896
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.
903
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.
907
908    Here are the functions for working with case tables:
909
910  - Function: case-table-p OBJECT
911      This predicate returns non-`nil' if OBJECT is a valid case table.
912
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.
916
917  - Function: standard-case-table
918      This returns the standard case table.
919
920  - Function: current-case-table
921      This function returns the current buffer's case table.
922
923  - Function: set-case-table TABLE
924      This sets the current buffer's case table to TABLE.
925
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::.
931
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.
935
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.
939
940  - Function: set-case-syntax CHAR SYNTAX DOWNCASE-TABLE
941      This function makes CHAR case-invariant, with syntax SYNTAX.
942
943  - Command: describe-buffer-case-table
944      This command displays a description of the contents of the current
945      buffer's case table.
946
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.
949
950 \1f
951 File: lispref.info,  Node: Char Tables,  Prev: Case Tables,  Up: Strings and Characters
952
953 The Char Table
954 ==============
955
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).
964
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.
968
969    When MULE support exists, the types of ranges that can be assigned
970 values are
971
972    * all characters
973
974    * an entire charset
975
976    * a single row in a two-octet charset
977
978    * a single character
979
980    When MULE support is not present, the types of ranges that can be
981 assigned values are
982
983    * all characters
984
985    * a single character
986
987  - Function: char-table-p OBJECT
988      This function returns non-`nil' if OBJECT is a char table.
989
990 * Menu:
991
992 * Char Table Types::            Char tables have different uses.
993 * Working With Char Tables::    Creating and working with char tables.
994
995 \1f
996 File: lispref.info,  Node: Char Table Types,  Next: Working With Char Tables,  Up: Char Tables
997
998 Char Table Types
999 ----------------
1000
1001    Each char table type is used for a different purpose and allows
1002 different sorts of values.  The different char table types are
1003
1004 `category'
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.
1010
1011 `char'
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.
1015
1016 `generic'
1017      An even more generalized char table, for mapping from a character
1018      to anything.
1019
1020 `display'
1021      Used for display tables, which specify how a particular character
1022      is to appear when displayed.  #### Not yet implemented.
1023
1024 `syntax'
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.
1028
1029  - Function: char-table-type TABLE
1030      This function returns the type of char table TABLE.
1031
1032  - Function: char-table-type-list
1033      This function returns a list of the recognized char table types.
1034
1035  - Function: valid-char-table-type-p TYPE
1036      This function returns `t' if TYPE if a recognized char table type.
1037
1038 \1f
1039 File: lispref.info,  Node: Working With Char Tables,  Prev: Char Table Types,  Up: Char Tables
1040
1041 Working With Char Tables
1042 ------------------------
1043
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'.
1048
1049  - Function: put-char-table RANGE VAL TABLE
1050      This function sets the value for chars in RANGE to be VAL in TABLE.
1051
1052      RANGE specifies one or more characters to be affected and should be
1053      one of the following:
1054
1055         * `t' (all characters are affected)
1056
1057         * A charset (only allowed when MULE support is present)
1058
1059         * A vector of two elements: a two-octet charset and a row number
1060           (only allowed when MULE support is present)
1061
1062         * A single character
1063
1064      VAL must be a value appropriate for the type of TABLE.
1065
1066  - Function: get-char-table CH TABLE
1067      This function finds the value for char CH in TABLE.
1068
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').
1072
1073  - Function: reset-char-table TABLE
1074      This function resets a char table to its default state.
1075
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.
1079
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.
1083
1084  - Function: valid-char-table-value-p VALUE CHAR-TABLE-TYPE
1085      This function returns non-`nil' if VALUE is a valid value for
1086      CHAR-TABLE-TYPE.
1087
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
1090      CHAR-TABLE-TYPE.
1091
1092 \1f
1093 File: lispref.info,  Node: Lists,  Next: Sequences Arrays Vectors,  Prev: Strings and Characters,  Up: Top
1094
1095 Lists
1096 *****
1097
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
1102 the whole list.
1103
1104 * Menu:
1105
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.
1116
1117 \1f
1118 File: lispref.info,  Node: Cons Cells,  Next: Lists as Boxes,  Up: Lists
1119
1120 Lists and Cons Cells
1121 ====================
1122
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."
1128
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.
1136
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.
1139
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).
1143
1144    The CDR of any nonempty list L is a list containing all the elements
1145 of L except the first.
1146
1147 \1f
1148 File: lispref.info,  Node: Lists as Boxes,  Next: List-related Predicates,  Prev: Cons Cells,  Up: Lists
1149
1150 Lists as Linked Pairs of Boxes
1151 ==============================
1152
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
1156 cons cells:
1157
1158       ---------------         ---------------
1159      | car   | cdr   |       | car   | cdr   |
1160      | tulip |   o---------->| lily  |  nil  |
1161      |       |       |       |       |       |
1162       ---------------         ---------------
1163
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.
1170
1171    The same list can be illustrated in a different sort of box notation
1172 like this:
1173
1174          ___ ___      ___ ___
1175         |___|___|--> |___|___|--> nil
1176           |            |
1177           |            |
1178            --> tulip    --> lily
1179
1180    Here is a more complex illustration, showing the three-element list,
1181 `((pine needles) oak maple)', the first element of which is a
1182 two-element list:
1183
1184          ___ ___      ___ ___      ___ ___
1185         |___|___|--> |___|___|--> |___|___|--> nil
1186           |            |            |
1187           |            |            |
1188           |             --> oak      --> maple
1189           |
1190           |     ___ ___      ___ ___
1191            --> |___|___|--> |___|___|--> nil
1192                  |            |
1193                  |            |
1194                   --> pine     --> needles
1195
1196    The same list represented in the first box notation looks like this:
1197
1198       --------------       --------------       --------------
1199      | car   | cdr  |     | car   | cdr  |     | car   | cdr  |
1200      |   o   |   o------->| oak   |   o------->| maple |  nil |
1201      |   |   |      |     |       |      |     |       |      |
1202       -- | ---------       --------------       --------------
1203          |
1204          |
1205          |        --------------       ----------------
1206          |       | car   | cdr  |     | car     | cdr  |
1207           ------>| pine  |   o------->| needles |  nil |
1208                  |       |      |     |         |      |
1209                   --------------       ----------------
1210
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.
1213
1214 \1f
1215 File: lispref.info,  Node: List-related Predicates,  Next: List Elements,  Prev: Lists as Boxes,  Up: Lists
1216
1217 Predicates on Lists
1218 ===================
1219
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.)
1224
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.
1228
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.
1233
1234           (atom OBJECT) == (not (consp OBJECT))
1235
1236  - Function: listp OBJECT
1237      This function returns `t' if OBJECT is a cons cell or `nil'.
1238      Otherwise, it returns `nil'.
1239
1240           (listp '(1))
1241                => t
1242           (listp '())
1243                => t
1244
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'.
1248
1249           (listp OBJECT) == (not (nlistp OBJECT))
1250
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::).
1257
1258           (null '(1))
1259                => nil
1260           (null '())
1261                => t
1262