home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i03 < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  50.9 KB  |  1,341 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  10. Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: elisp,  Node: Keymap Type,  Next: Syntax Table Type,  Prev: Stream Type,  Up: Editing Types
  30.  
  31. Keymap Type
  32. -----------
  33.  
  34.    A "keymap" maps keys typed by the user to functions.  This mapping
  35. controls how the user's command input is executed.  Emacs defines two
  36. kinds of keymaps: "full keymaps", which are vectors of 128 elements,
  37. and "sparse keymaps", which are association lists whose first element
  38. is the symbol `keymap'.
  39.  
  40.    *Note Keymaps::, for information about creating keymaps, handling
  41. prefix keys, local as well as global keymaps, and changing key bindings.
  42.  
  43. 
  44. File: elisp,  Node: Syntax Table Type,  Prev: Keymap Type,  Up: Editing Types
  45.  
  46. Syntax Table Type
  47. -----------------
  48.  
  49.    A "syntax table" is a vector of 256 integers.  Each element of the
  50. vector defines how one character is interpreted when it appears in a
  51. buffer.  For example, in C mode (*note Major Modes::.), the `+'
  52. character is punctuation, but in Lisp mode it is a valid character in a
  53. symbol.  These different interpretations are effected by changing the
  54. syntax table entry for `+', i.e., at index 43.
  55.  
  56.    Syntax tables are only used for scanning text in buffers, not for
  57. reading Lisp expressions.  The table the Lisp interpreter uses to read
  58. expressions is built into the Emacs source code and cannot be changed;
  59. thus, to change the list delimiters to be `{' and `}' instead of `('
  60. and `)' would be impossible.
  61.  
  62.    *Note Syntax Tables::, for details about syntax classes and how to
  63. make and modify syntax tables.
  64.  
  65. 
  66. File: elisp,  Node: Type Predicates,  Next: Equality Predicates,  Prev: Editing Types,  Up: Types of Lisp Object
  67.  
  68. Type Predicates
  69. ===============
  70.  
  71.    The Emacs Lisp interpreter itself does not perform type checking on
  72. the actual arguments passed to functions when they are called.  It could
  73. not do otherwise, since variables in Lisp are not declared to be of a
  74. certain type, as they are in other programming languages.  It is
  75. therefore up to the individual function to test whether each actual
  76. argument belongs to a type that can be used by the function.
  77.  
  78.    All built-in functions do check the types of their actual arguments
  79. when appropriate and signal a `wrong-type-argument' error if an
  80. argument is of the wrong type.  For example, here is what happens if you
  81. pass an argument to `+' which it cannot handle:
  82.  
  83.      (+ 2 'a)
  84.           error--> Wrong type argument: integer-or-marker-p, a
  85.  
  86.    Many functions, called "type predicates", are provided to test
  87. whether an object is a member of a given type.  (Following a convention
  88. of long standing, the names of most Emacs Lisp predicates end in `p'.)
  89.  
  90.    Here is a table of predefined type predicates, in alphabetical order,
  91. with references to further information.
  92.  
  93. `atom'
  94.      *note atom: List-related Predicates.
  95.  
  96. `arrayp'
  97.      *note arrayp: Array Functions.
  98.  
  99. `bufferp'
  100.      *note bufferp: Buffer Basics.
  101.  
  102. `char-or-string-p'
  103.      *note char-or-string-p: Predicates for Strings.
  104.  
  105. `consp'
  106.      *note consp: List-related Predicates.
  107.  
  108. `integer-or-marker-p'
  109.      *note integer-or-marker-p: Predicates on Markers.
  110.  
  111. `integerp'
  112.      *note integerp: Predicates on Numbers.
  113.  
  114. `keymapp'
  115.      *note keymapp: Creating Keymaps.
  116.  
  117. `listp'
  118.      *note listp: List-related Predicates.
  119.  
  120. `markerp'
  121.      *note markerp: Predicates on Markers.
  122.  
  123. `natnump'
  124.      *note natnump: Predicates on Numbers.
  125.  
  126. `nlistp'
  127.      *note nlistp: List-related Predicates.
  128.  
  129. `processp'
  130.      *note processp: Processes.
  131.  
  132. `sequencep'
  133.      *note sequencep: Sequence Functions.
  134.  
  135. `stringp'
  136.      *note stringp: Predicates for Strings.
  137.  
  138. `subrp'
  139.      *note subrp: Function Cells.
  140.  
  141. `symbolp'
  142.      *note symbolp: Symbols.
  143.  
  144. `syntax-table-p'
  145.      *note syntax-table-p: Syntax Tables.
  146.  
  147. `user-variable-p'
  148.      *note user-variable-p: Defining Variables.
  149.  
  150. `vectorp'
  151.      *note vectorp: Vectors.
  152.  
  153. `windowp'
  154.      *note windowp: Basic Windows.
  155.  
  156. 
  157. File: elisp,  Node: Equality Predicates,  Prev: Type Predicates,  Up: Types of Lisp Object
  158.  
  159. Equality Predicates
  160. ===================
  161.  
  162.    Here we describe two functions that test for equality between any two
  163. objects.  Other functions test equality between objects of specific
  164. types, e.g., strings.  See the appropriate chapter describing the data
  165. type for these predicates.
  166.  
  167.  -- Function: eq OBJECT1 OBJECT2
  168.      This function returns `t' if OBJECT1 and OBJECT2 are the same
  169.      object, `nil' otherwise.  The "same object" means that a change in
  170.      one will be reflected by the same change in the other.
  171.  
  172.      `eq' will be true if OBJECT1 and OBJECT2 are numbers with the same
  173.      value.  Also, since symbol names are normally unique, if the
  174.      arguments are symbols with the same name, they are `eq'.  For
  175.      other types (e.g., lists, vectors, strings), two arguments with
  176.      the same contents or elements are not necessarily `eq' to each
  177.      other: they are `eq' only if they are the same object.
  178.  
  179.      (The `make-symbol' function returns an uninterned symbol that is
  180.      not interned in the standard `obarray'.  When uninterned symbols
  181.      are in use, symbol names are no longer unique.  Distinct symbols
  182.      with the same name are not `eq'.  *Note Creating Symbols::.)
  183.  
  184.           (eq 'foo 'foo)
  185.                => t
  186.           
  187.           (eq 456 456)
  188.                => t
  189.           
  190.           (eq "asdf" "asdf")
  191.                => nil
  192.           
  193.           (eq '(1 (2 (3))) '(1 (2 (3))))
  194.                => nil
  195.           
  196.           (eq [(1 2) 3] [(1 2) 3])
  197.                => nil
  198.           
  199.           (eq (point-marker) (point-marker))
  200.                => nil
  201.  
  202.  
  203.  -- Function: equal OBJECT1 OBJECT2
  204.      This function returns `t' if OBJECT1 and OBJECT2 have equal
  205.      components, `nil' otherwise.  Whereas `eq' tests if its arguments
  206.      are the same object, `equal' looks inside nonidentical arguments
  207.      to see if their elements are the same.  So, if two objects are
  208.      `eq', they are `equal', but the converse is not always true.
  209.  
  210.           (equal 'foo 'foo)
  211.                => t
  212.           
  213.           (equal 456 456)
  214.                => t
  215.           
  216.           (equal "asdf" "asdf")
  217.                => t
  218.           (eq "asdf" "asdf")
  219.                => nil
  220.           
  221.           (equal '(1 (2 (3))) '(1 (2 (3))))
  222.                => t
  223.           (eq '(1 (2 (3))) '(1 (2 (3))))
  224.                => nil
  225.           
  226.           (equal [(1 2) 3] [(1 2) 3])
  227.                => t
  228.           (eq [(1 2) 3] [(1 2) 3])
  229.                => nil
  230.           
  231.           (equal (point-marker) (point-marker))
  232.                => t
  233.           (eq (point-marker) (point-marker))
  234.                => nil
  235.  
  236.      Comparison of strings is case-sensitive.
  237.  
  238.           (equal "asdf" "ASDF")
  239.                => nil
  240.  
  241.    The test for equality is implemented recursively, and circular lists
  242. may therefore cause infinite recursion (leading to an error).
  243.  
  244. 
  245. File: elisp,  Node: Numbers,  Next: Strings and Characters,  Prev: Types of Lisp Object,  Up: Top
  246.  
  247. Numbers
  248. *******
  249.  
  250.    Integers are the only kind of number in version 18 Emacs Lisp.  These
  251. are whole numbers such as -3, 0, 7, 13, and 511.
  252.  
  253.    In version 19, there is a compile time option to support floating
  254. point numbers, which are represented internally as the C type `double'.
  255. A floating point number is a number with a fractional part, such as
  256. -4.5, 0.0, or 2.71828.  A floating point number can be expressed in an
  257. exponential notation as well: thus, 1.5e2 equals 150; in this example,
  258. `e2' stands for ten to the second power, and is multiplied by 1.5.
  259.  
  260. * Menu:
  261.  
  262. * Number Basics::             Representation and range of numbers.
  263. * Predicates on Numbers::     Testing for numbers.
  264. * Comparison of Numbers::     Equality and inequality predicates.
  265. * Arithmetic Operations::     How to add, subtract, multiply and divide.
  266. * Bitwise Operations::        Logical and, or, not, shifting.
  267. * Random Numbers::            Obtaining random integers, predictable or not.
  268.  
  269. 
  270. File: elisp,  Node: Number Basics,  Next: Predicates on Numbers,  Prev: Numbers,  Up: Numbers
  271.  
  272. Number Basics
  273. =============
  274.  
  275.    The range of values for an integer depends on the machine.  The
  276. range is -8388608 to 8388607 (24 bits; i.e., -2**23 to 2**23 - 1 ) on
  277. most machines, but on others it is -16777216 to 16777215 (25 bits), or
  278. -33554432 to 33554431 (26 bits).  All of the examples shown below
  279. assume an integer has 24 bits.
  280.  
  281.    The Lisp reader reads numbers as a sequence of digits with an
  282. optional sign.
  283.  
  284.      1                ; The integer 1.
  285.      +1               ; Also the integer 1.
  286.      -1               ; The integer -1.
  287.      16777217         ; Also the integer 1, due to overflow.
  288.      0                ; The number 0.
  289.      -0               ; The number 0.
  290.      1.               ; Invalid syntax.
  291.  
  292.    To understand how various functions work on integers, especially the
  293. bitwise operators (*note Bitwise Operations::.), it is often helpful to
  294. view the numbers in their binary form.
  295.  
  296.    In 24 bit binary, the decimal integer 5 looks like this:
  297.  
  298.      0000 0000  0000 0000  0000 0101
  299.  
  300. (We have inserted spaces between groups of 4 bits, and two spaces
  301. between groups of 8 bits, to make the binary integer easier to read.)
  302.  
  303.    The integer -1 looks like this:
  304.  
  305.      1111 1111  1111 1111  1111 1111
  306.  
  307. -1 is represented as 24 ones.  (This is called "two's complement"
  308. notation.)
  309.  
  310.    The negative integer, -5, is creating by subtracting 4 from -1.  In
  311. binary, the decimal integer 4 is 100.  Consequently, -5 looks like this:
  312.  
  313.      1111 1111  1111 1111  1111 1011
  314.  
  315.    In this implementation, the largest 24 bit binary integer is the
  316. decimal integer 8,388,607.  In binary, this number looks like this:
  317.  
  318.      0111 1111  1111 1111  1111 1111
  319.  
  320.    Since the arithmetic functions do not check whether integers go
  321. outside their range, when you add 1 to 8,388,607, the value is negative
  322. integer -8,388,608:
  323.  
  324.      (+ 1 8388607)
  325.           => -8388608
  326.           => 1000 0000  0000 0000  0000 0000
  327.  
  328.    Many of the following functions accept markers for arguments as well
  329. as integers.  (*Note Markers::.)  More precisely, the actual parameters
  330. to such functions may be either integers or markers, which is why we
  331. often give these parameters the name MARKER-OR-INT.  When the actual
  332. parameter is a marker, the position value of the marker is used and the
  333. buffer of the marker is ignored.
  334.  
  335. 
  336. File: elisp,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Number Basics,  Up: Numbers
  337.  
  338. Type Predicates for Numbers
  339. ===========================
  340.  
  341.    The functions in this section test whether the argument is a number
  342. or whether it is a certain sort of number.  `integerp' and `natnump'
  343. can take any type of Lisp object as argument (the predicates would not
  344. be of much use otherwise); but the `zerop' predicate requires an
  345. integer as its argument.
  346.  
  347.  -- Function: integerp OBJECT
  348.      This predicate tests whether its argument is an integer (a whole
  349.      number) and returns `t' if so, `nil' otherwise.
  350.  
  351.  -- Function: natnump OBJECT
  352.      The `natnump' predicate (whose name comes from the phrase
  353.      "natural-number-p") tests to see whether its argument is a
  354.      nonnegative integer, and returns `t' if so, `nil' otherwise.  0 is
  355.      considered non-negative.
  356.  
  357.      Markers are not converted to integers, hence `natnump' of a marker
  358.      is always `nil'.
  359.  
  360.      People have pointed out that this function is misnamed, because
  361.      the term "natural number" is usually understood as excluding zero.
  362.       We are open to suggestions for a better name to use in version 19.
  363.  
  364.  -- Function: zerop INTEGER
  365.      This predicate tests whether its argument is zero, and returns `t'
  366.      if so, `nil' otherwise.  These two forms are equivalent: `(zerop x)
  367.      == (= x 0)'.
  368.  
  369. 
  370. File: elisp,  Node: Comparison of Numbers,  Next: Arithmetic Operations,  Prev: Predicates on Numbers,  Up: Numbers
  371.  
  372. Comparison of Numbers
  373. =====================
  374.  
  375.    The integer type is implemented by storing the value in the "pointer
  376. part" of a Lisp object (which, on typical target machines, has 24 bits
  377. of pointer, 7 bits of type and 1 bit for the garbage collector).
  378. Because of this, the function `eq' will return `t' for two integers
  379. with the same value.  *Note Equality Predicates::.
  380.  
  381.      Common Lisp note: because of the way numbers are implemented in
  382.      Common Lisp, you generally need to use ``='' to test for equality
  383.      between numbers.  However, GNU Emacs Lisp does not need very large
  384.      integers; as a consequence, it is possible to restrict them to the
  385.      size of a single word, allowing `eq' to be used.
  386.  
  387.  -- Function: = MARKER-OR-INT1 MARKER-OR-INT2
  388.      This function tests whether its arguments are the same number, and
  389.      returns `t' if so, `nil' otherwise.
  390.  
  391.  -- Function: /= MARKER-OR-INT1 MARKER-OR-INT2
  392.      This function tests whether its arguments are not the same number,
  393.      and returns `t' if so, `nil' otherwise.
  394.  
  395.  -- Function: < MARKER-OR-INT1 MARKER-OR-INT2
  396.      This function tests whether its first argument is strictly less
  397.      than its second argument.  It returns `t' if so, `nil' otherwise.
  398.  
  399.  -- Function: <= MARKER-OR-INT1 MARKER-OR-INT2
  400.      This function tests whether its first argument is less than or
  401.      equal to its second argument.  It returns `t' if so, `nil'
  402.      otherwise.
  403.  
  404.  -- Function: > MARKER-OR-INT1 MARKER-OR-INT2
  405.      This function tests whether its first argument is strictly greater
  406.      than its second argument.  It returns `t' if so, `nil' otherwise.
  407.  
  408.  -- Function: >= MARKER-OR-INT1 MARKER-OR-INT2
  409.      This function tests whether its first argument is greater than or
  410.      equal to its second argument.  It returns `t' if so, `nil'
  411.      otherwise.
  412.  
  413.  -- Function: max MARKER-OR-INT &rest MARKERS-OR-INTS
  414.      This function returns the largest of its arguments.
  415.  
  416.           (max 20)
  417.                => 20
  418.           (max 1 2)
  419.                => 2
  420.           (max 1 3 2)
  421.                => 3
  422.  
  423.  -- Function: min MARKER-OR-INT &rest MARKERS-OR-INTS
  424.      This function returns the smallest of its arguments.
  425.  
  426. 
  427. File: elisp,  Node: Arithmetic Operations,  Next: Bitwise Operations,  Prev: Comparison of Numbers,  Up: Numbers
  428.  
  429. Arithmetic Operations
  430. =====================
  431.  
  432.    Emacs Lisp provides the traditional four arithmetic operations:
  433. addition, subtraction, multiplication, and division.  A remainder
  434. function supplements the (integer) division function.  In addition, as
  435. a convenience, incrementing and decrementing functions are provided.
  436.  
  437.    It is important to note that in GNU Emacs Lisp, arithmetic functions
  438. do not check for overflow.  Thus `(1+ 8388607)' may equal -8388608,
  439. depending on your hardware.
  440.  
  441.  -- Function: 1+ MARKER-OR-INT
  442.      This function adds one to MARKER-OR-INT.
  443.  
  444.  -- Function: 1- MARKER-OR-INT
  445.      This function subtracts one from MARKER-OR-INT.
  446.  
  447.  -- Function: + &rest MARKERS-OR-INTS
  448.      This function adds its arguments together.  When given no
  449.      arguments, `+' returns 0.  It does not check for overflow.
  450.  
  451.           (+)
  452.                => 0
  453.           (+ 1)
  454.                => 1
  455.           (+ 1 2 3 4)
  456.                => 10
  457.  
  458.  -- Function: - &optional MARKER-OR-INT &rest OTHER-MARKERS-OR-INTS
  459.      The `-' function serves two purposes: negation and subtraction.
  460.      When `-' has a single argument, the value is the negative of the
  461.      argument.  When there are multiple arguments, each of the
  462.      OTHER-MARKERS-OR-INTS is subtracted from MARKER-OR-INT,
  463.      cumulatively.  If there are no arguments, the result is 0.  This
  464.      function does not check for overflow.
  465.  
  466.           (- 10 1 2 3 4)
  467.                => 0
  468.           (- 10)
  469.                => -10
  470.           (-)
  471.                => 0
  472.  
  473.  -- Function: * &rest MARKERS-OR-INTEGERS
  474.      This function multiplies its arguments together, and returns the
  475.      product.  When given no arguments, `*' returns 1.  It does not
  476.      check for overflow.
  477.  
  478.           (*)
  479.                => 1
  480.           (* 1)
  481.                => 1
  482.           (* 1 2 3 4)
  483.                => 24
  484.  
  485.  -- Function: / DIVIDEND DIVISOR &rest DIVISORS
  486.      This function divides DIVIDEND by DIVISORS and returns the
  487.      quotient.  If there are additional arguments DIVISORS, then
  488.      DIVIDEND is divided by each divisor in turn.    Each argument may
  489.      be an integer or a marker.
  490.  
  491.      The result is normally rounded towars zero after each division,
  492.      but some machines may round differently with negative arguments. 
  493.      This is because the Lisp function `/' is implemented using the C
  494.      division operator, which has the same possibility for
  495.      machine-dependent rounding. In practice, all known machines round
  496.      in the standard fashion.
  497.  
  498.      If you divide by 0, an `arith-error' error is signaled. (*Note
  499.      Errors::.)
  500.  
  501.           (/ 6 2)
  502.                => 3
  503.           (/ 5 2)
  504.                => 2
  505.           (/ 25 3 2)
  506.                => 4
  507.           (/ -17 6)
  508.                => -2          ; (Could be -3 on some machines.)
  509.  
  510.  -- Function: % DIVIDEND DIVISOR
  511.      This function returns the value of DIVIDEND modulo DIVISOR; in
  512.      other words, the integer remainder after division of DIVIDEND by
  513.      DIVISOR.  The sign of the result is the sign of DIVIDEND. The sign
  514.      of DIVISOR is ignored.  The arguments must be integers.
  515.  
  516.      For negative arguments, the value is in principle machine-dependent
  517.      since the quotient is; but in practice, all known machines behave
  518.      alike.
  519.  
  520.      An `arith-error' results if DIVISOR is 0.
  521.  
  522.           (% 9 4)
  523.                => 1
  524.           (% -9 4)
  525.                => -1
  526.           (% 9 -4)
  527.                => 1
  528.           (% -9 -4)
  529.                => -1
  530.  
  531.      For any two numbers DIVIDEND and DIVISOR,
  532.  
  533.           (+ (% DIVIDEND DIVISOR)
  534.              (* (/ DIVIDEND DIVISOR) DIVISOR))
  535.  
  536.      always equals DIVIDEND.
  537.  
  538. 
  539. File: elisp,  Node: Bitwise Operations,  Next: Random Numbers,  Prev: Arithmetic Operations,  Up: Numbers
  540.  
  541. Bitwise Operations on Integers
  542. ==============================
  543.  
  544.    In a computer, an integer is represented as a binary number, a
  545. sequence of "bits" (digits which are either zero or one).  A bitwise
  546. operation acts on the individual bits of such a sequence.  For example,
  547. "shifting" moves the whole sequence left or right one or more places,
  548. reproducing the same pattern "moved over".
  549.  
  550.    The bitwise operations in Emacs Lisp apply only to integers.
  551.  
  552.  -- Function: lsh INTEGER1 COUNT
  553.      `lsh', which is an abbreviation for "logical shift", shifts the
  554.      bits in INTEGER1 to the left COUNT places, or to the right if
  555.      COUNT is negative.  If COUNT is negative, `lsh' shifts zeros into
  556.      the most-significant bit, producing a positive result even if
  557.      INTEGER1 is negative.  Contrast this with `ash', below.
  558.  
  559.      Thus, the decimal number 5 is the binary number 00000101.  Shifted
  560.      once to the left, with a zero put in the one's place, the number
  561.      becomes 00001010, decimal 10.
  562.  
  563.      Here are two examples of shifting the pattern of bits one place to
  564.      the left.  Since the contents of the rightmost place has been
  565.      moved one place to the left, a value has to be inserted into the
  566.      rightmost place. With `lsh', a zero is placed into the rightmost
  567.      place.  (These examples show only the low-order eight bits of the
  568.      binary pattern; the rest are all zero.)
  569.  
  570.           (lsh 5 1)
  571.                => 10
  572.           
  573.           00000101 => 00001010     ; Decimal 5 becomes decimal 10.
  574.           
  575.           (lsh 7 1)
  576.                => 14
  577.           
  578.           00000111 => 00001110     ; Decimal 7 becomes decimal 14.
  579.  
  580.      As the examples illustrate, shifting the pattern of bits one place
  581.      to the left produces a number that is twice the value of the
  582.      previous number.
  583.  
  584.      Note, however that functions do not check for overflow, and a
  585.      returned value may be negative (and in any case, no more than a 24
  586.      bit value) when an integer is sufficiently left shifted.  For
  587.      example:
  588.  
  589.           (lsh 8388607 1)          ; left shift
  590.                => -2
  591.  
  592.      In binary, in the 24 bit implementation,
  593.  
  594.           0111 1111  1111 1111  1111 1111         ; Decimal 8,388,607
  595.  
  596.      becomes
  597.  
  598.           1111 1111  1111 1111  1111 1110         ; Decimal -2
  599.  
  600.      Shifting the pattern of bits two places to the left produces
  601.      results like this (with 8-bit binary numbers):
  602.  
  603.           (lsh 3 2)
  604.                => 12
  605.           
  606.           00000011 => 00001100       ; Decimal 3 becomes decimal 12.
  607.  
  608.      On the other hand, shifting the pattern of bits one place to the
  609.      right looks like this:
  610.  
  611.           (lsh 6 -1)
  612.                => 3
  613.           
  614.           00000110 => 00000011       ; Decimal 6 becomes decimal 3.
  615.           
  616.           (lsh 5 -1)
  617.                => 2
  618.           
  619.           00000101 => 00000010       ; Decimal 5 becomes decimal 2.
  620.  
  621.      As the example illustrates, shifting the pattern of bits one place
  622.      to the right divides the value of the binary number by two,
  623.      rounding downward.
  624.  
  625.  -- Function: ash INTEGER1 COUNT
  626.      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the left
  627.      COUNT places, or to the right if COUNT is negative.
  628.  
  629.      `ash' gives the same results as `lsh' except when INTEGER1 and
  630.      COUNT are both negative.  In that case, `ash' puts a one in the
  631.      leftmost position, while `lsh' puts a zero in the leftmost
  632.      position.
  633.  
  634.      Thus, with `ash', shifting the pattern of bits one place to the
  635.      right looks like this:
  636.  
  637.           (ash -6 -1)
  638.                => -3            ; Decimal -6 becomes decimal -3.
  639.           
  640.           1111 1111  1111 1111  1111 1010
  641.                =>
  642.           1111 1111  1111 1111  1111 1101
  643.  
  644.      In contrast, shifting the pattern of bits one place to the right
  645.      with `lsh' looks like this:
  646.  
  647.           (lsh -6 -1)
  648.                => 8388605       ; Decimal -6 becomes decimal 8,388,605.
  649.           
  650.           1111 1111  1111 1111  1111 1010
  651.                =>
  652.           0111 1111  1111 1111  1111 1101
  653.  
  654.      In this case, the 1 in the leftmost position is shifted one place
  655.      to the right, and a zero is shifted into the leftmost position.
  656.  
  657.      Here are other examples:
  658.  
  659.                                  ;               24-bit binary values
  660.           
  661.           (lsh 5 2)              ;   5  =  0000 0000  0000 0000  0000 0101
  662.                => 20             ;  20  =  0000 0000  0000 0000  0001 0100
  663.           (ash 5 2)
  664.                => 20
  665.           (lsh -5 2)             ;  -5  =  1111 1111  1111 1111  1111 1011
  666.                => -20            ; -20  =  1111 1111  1111 1111  1110 1100
  667.           (ash -5 2)
  668.                => -20
  669.           
  670.           (lsh 5 -2)             ;   5  =  0000 0000  0000 0000  0000 0101
  671.                => 1              ;   1  =  0000 0000  0000 0000  0000 0001
  672.           (ash 5 -2)
  673.                => 1
  674.           (lsh -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  675.                => 4194302        ;         0011 1111  1111 1111  1111 1110
  676.           (ash -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  677.                => -2             ;  -2  =  1111 1111  1111 1111  1111 1110
  678.  
  679.  -- Function: logand &rest MARKERS-OR-INTS
  680.      This function returns the "logical and" of the arguments: the Nth
  681.      bit is set in the result if, and only if, the Nth bit is set in
  682.      all the arguments.  ("Set" means that the value of the bit is 1
  683.      rather than 0.)
  684.  
  685.      For example, using 4-bit binary numbers, the "logical and" of 13
  686.      and 12 is 12: 1101 combined with 1100 produces 1100.
  687.  
  688.      In both the binary numbers, the leftmost two bits are set (i.e.,
  689.      they are 1's), so the leftmost two bits of the returned value are
  690.      set. However, for the rightmost two bits, each is zero in at least
  691.      one of the arguments, so the rightmost two bits of the returned
  692.      value are 0's.
  693.  
  694.      Therefore,
  695.  
  696.           (logand 13 12)
  697.                => 12
  698.  
  699.      If `logand' is not passed any argument, it returns a value of -1. 
  700.      This number is an identity element for `logand' because its binary
  701.      representation consists entirely of ones.  If `logand' is passed
  702.      just one argument, it returns that argument.
  703.  
  704.                                  ;                24-bit binary values
  705.           
  706.           (logand 14 13)         ; 14  =  0000 0000  0000 0000  0000 1110
  707.                                  ; 13  =  0000 0000  0000 0000  0000 1101
  708.                => 12             ; 12  =  0000 0000  0000 0000  0000 1100
  709.           
  710.           (logand 14 13 4)       ; 14  =  0000 0000  0000 0000  0000 1110
  711.                                  ; 13  =  0000 0000  0000 0000  0000 1101
  712.                                  ;  4  =  0000 0000  0000 0000  0000 0100
  713.                => 4              ;  4  =  0000 0000  0000 0000  0000 0100
  714.           
  715.           (logand)
  716.                => -1             ; -1  =  1111 1111  1111 1111  1111 1111
  717.  
  718.  -- Function: logior &rest MARKERS-OR-INTS
  719.      This function returns the "inclusive or" of its arguments: the Nth
  720.      bit is set in the result if, and only if, the Nth bit is set in at
  721.      least one of the arguments.  If there are no arguments, the result
  722.      is zero, which is an identity element for this operation.  If
  723.      `logior' is passed just one argument, it returns that argument.
  724.  
  725.                                  ;               24-bit binary values
  726.           
  727.           (logior 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  728.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  729.                => 13             ; 13  =  0000 0000  0000 0000  0000 1101
  730.           
  731.           (logior 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  732.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  733.                                  ;  7  =  0000 0000  0000 0000  0000 0111
  734.                => 15             ; 15  =  0000 0000  0000 0000  0000 1111
  735.  
  736.  -- Function: logxor &rest MARKERS-OR-INTS
  737.      This function returns the "exclusive or" of its arguments: the Nth
  738.      bit is set in the result if, and only if, the Nth bit is set in an
  739.      odd number of the arguments.  If there are no arguments, the
  740.      result is 0.  If `logxor' is passed just one argument, it returns
  741.      that argument.
  742.  
  743.                                  ;               24-bit binary values
  744.           
  745.           (logxor 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  746.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  747.                => 9              ;  9  =  0000 0000  0000 0000  0000 1001
  748.           
  749.           (logxor 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  750.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  751.                                  ;  7  =  0000 0000  0000 0000  0000 0111
  752.                => 14             ; 14  =  0000 0000  0000 0000  0000 1110
  753.  
  754.  -- Function: lognot INTEGER
  755.      This function returns the logical complement of its argument: the
  756.      Nth bit is one in the result if, and only if, the Nth bit is zero
  757.      in INTEGER, and vice-versa.
  758.  
  759.           (lognot 5)             ;  5  =  0000 0000  0000 0000  0000 0101
  760.                => -6             ; -6  =  1111 1111  1111 1111  1111 1010
  761.  
  762. 
  763. File: elisp,  Node: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
  764.  
  765. Random Numbers
  766. ==============
  767.  
  768.  -- Function: random &optional FLAG
  769.      This function returns a pseudo-random number of type integer.  When
  770.      called more than once, this function returns a series of
  771.      pseudo-random numbers.
  772.  
  773.      In a computer, a series of a pseudo-random numbers is generated in
  774.      a deterministic fashion.  The numbers are not truly random, but
  775.      they have certain properties that mimic a random series.  For
  776.      example, all possible values occur equally often in a
  777.      pseudo-random series.
  778.  
  779.      In Emacs, pseudo-random numbers are generated from a "seed" number.
  780.      If the `random' function starts with the same seed, it generates
  781.      the same sequence of numbers.  Emacs always starts with the same
  782.      seed value, so the sequence of values of `random' is actually the
  783.      same in each Emacs run!  For example, in one operating system, the
  784.      first call to `(random)' after you start Emacs always returns
  785.      -1457731, and the second one always returns -7692030.  This is
  786.      helpful for debugging.
  787.  
  788.      If you want different random numbers, execute `(random t)'.  This
  789.      chooses a new seed based on the current time of day and on Emacs'
  790.      process ID number.
  791.  
  792.      On some machines, any integer representable in Lisp may be the
  793.      result of `random'.  On other machines, the result can never be
  794.      larger than a certain maximum or less than a certain (negative)
  795.      minimum.
  796.  
  797. 
  798. File: elisp,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
  799.  
  800. Strings and Characters
  801. **********************
  802.  
  803.    A string in Emacs Lisp is an array that contains an ordered sequence
  804. of characters.  Strings are used as names of symbols, buffers, and
  805. files, to send messages to users, to hold text being copied between
  806. buffers, and for many other purposes.  Because strings are so
  807. important, many functions are provided expressly for manipulating them.
  808.  Emacs Lisp programs use strings more often than individual characters.
  809.  
  810. * Menu:
  811.  
  812. * Intro to Strings::          Basic properties of strings and characters.
  813. * Predicates for Strings::    Testing whether an object is a string or char.
  814. * Creating Strings::          Functions to allocate new strings.
  815. * Text Comparison::           Comparing characters or strings.
  816. * String Conversion::         Converting characters or strings and vice versa.
  817. * Formatting Strings::        `format': Emacs's analog of `printf'.
  818. * Character Case::            Case conversion functions.
  819.  
  820. 
  821. File: elisp,  Node: Intro to Strings,  Next: Predicates for Strings,  Prev: Strings and Characters,  Up: Strings and Characters
  822.  
  823. Introduction to Strings and Characters
  824. ======================================
  825.  
  826.    Characters are represented in Emacs Lisp as integers; whether an
  827. integer was intended as a character or not is determined only by how it
  828. is used.  Strings in Emacs Lisp are arrays that contain an ordered
  829. sequence of characters.
  830.  
  831.    The length of a string (like any array) is fixed and independent of
  832. the string contents, and cannot be altered.  Strings in Lisp are *not*
  833. terminated by a distinguished character code.  (By contrast, strings in
  834. C are terminated by a character with ASCII code 0.) This means that any
  835. character, including the null character (ASCII code 0), is a valid
  836. element of a string.
  837.  
  838.    Since strings are considered arrays, you can operate on them with the
  839. general array functions.  (*Note Sequences Arrays Vectors::.)  For
  840. example, you can access or change individual characters in a string
  841. using the functions `aref' and `aset' (*note Array Functions::.).
  842.  
  843.    Each character in a string is stored in a single byte.  Therefore,
  844. numbers not in the range 0 to 255 are truncated when stored into a
  845. string.  This means that a string takes up much less memory than a
  846. vector of the same length.
  847.  
  848.    *Note Text::, for information about functions that display strings or
  849. copy them into buffers.  *Note Character Type::, and *Note String
  850. Type::, for information about the syntax of characters and strings.
  851.  
  852. 
  853. File: elisp,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: Intro to Strings,  Up: Strings and Characters
  854.  
  855. The Predicates for Strings
  856. ==========================
  857.  
  858.    For more information about general sequence and array predicates,
  859. see *Note Sequences Arrays Vectors::, and *Note Arrays::.
  860.  
  861.  -- Function: stringp OBJECT
  862.      This function returns `t' if OBJECT is a string, `nil' otherwise.
  863.  
  864.  -- Function: char-or-string-p OBJECT
  865.      This function returns `t' if OBJECT is a string or a character
  866.      (i.e., an integer), `nil' otherwise.
  867.  
  868. 
  869. File: elisp,  Node: Creating Strings,  Next: Text Comparison,  Prev: Predicates for Strings,  Up: Strings and Characters
  870.  
  871. Creating Strings
  872. ================
  873.  
  874.    The following functions create strings, either from scratch, or by
  875. putting strings together, or by taking them apart.
  876.  
  877.  -- Function: make-string COUNT CHARACTER
  878.      This function returns a string made up of COUNT repetitions of
  879.      CHARACTER.  If COUNT is negative, an error is signaled.
  880.  
  881.           (make-string 5 ?x)
  882.                => "xxxxx"
  883.           (make-string 0 ?x)
  884.                => ""
  885.  
  886.      Other functions to compare with this one include `char-to-string'
  887.      (*note String Conversion::.), `make-vector' (*note Vectors::.), and
  888.      `make-list' (*note Building Lists::.).
  889.  
  890.  -- Function: substring STRING START &optional END
  891.      This function returns a new string which consists of those
  892.      characters from STRING in the range from (and including) the
  893.      character at the index START up to (but excluding) the character
  894.      at the index END.  The first character is at index zero.
  895.  
  896.           (substring "abcdefg" 0 3)
  897.                => "abc"
  898.  
  899.      Here the index for `a' is 0, the index for `b' is 1, and the index
  900.      for `c' is 2.  Thus, three letters, `abc', are copied from the
  901.      full string.  The index 3 marks the character position up to which
  902.      the substring is copied.  The character whose index is 3 is
  903.      actually the fourth character in the string.
  904.  
  905.      A negative number counts from the end of the string, so that -1
  906.      signifies the index of the last character of the string.  For
  907.      example:
  908.  
  909.           (substring "abcdefg" -3 -1)
  910.                => "ef"
  911.  
  912.      In this example, the index for `e' is -3, the index for `f' is -2,
  913.      and the index for `g' is -1. Therefore, `e' and `f' are included,
  914.      and `g' is excluded.
  915.  
  916.      When `nil' is used as an index, it falls after the last character
  917.      in the string.  Thus:
  918.  
  919.           (substring "abcdefg" -3 nil)
  920.                => "efg"
  921.  
  922.      Omitting the argument END is equivalent to specifying `nil'. It
  923.      follows that `(substring STRING 0)' returns a copy of all of
  924.      STRING.
  925.  
  926.           (substring "abcdefg" 0)
  927.                => "abcdefg"
  928.  
  929.      But we recommend `copy-sequence' for this purpose.
  930.  
  931.      A `wrong-type-argument' error is signaled if either START or END
  932.      are non-integers.  An `args-out-of-range' error is signaled if
  933.      START indicates a character following END, or if either integer is
  934.      out of range for STRING.
  935.  
  936.      Contrast this function with `buffer-substring' (*note Buffer
  937.      Contents::.), which returns a string containing a portion of the
  938.      text in the current buffer.  The beginning of a string is at index
  939.      0, but the beginning of a buffer is at index 1.
  940.  
  941.  -- Function: concat &rest SEQUENCES
  942.      This function returns a new string consisting of the characters in
  943.      the arguments passed to it.  The arguments may be strings, lists
  944.      of numbers, or vectors of numbers; they are not themselves
  945.      changed.  If no arguments are passed to `concat', it returns an
  946.      empty string.
  947.  
  948.           (concat "abc" "-def")
  949.                => "abc-def"
  950.           (concat "abc" (list 120 (+ 256 121)) [122])
  951.                => "abcxyz"
  952.           (concat "The " "quick brown " "fox.")
  953.                => "The quick brown fox."
  954.           (concat)
  955.                => ""
  956.  
  957.      The second example above shows how characters stored in strings are
  958.      taken modulo 256.  In other words, each character in the string is
  959.      stored in one byte.
  960.  
  961.      The `concat' function always constructs a new string that is not
  962.      `eq' to any existing string.
  963.  
  964.      When an argument is an integer (not a sequence of integers), it is
  965.      converted to a string of digits making up the decimal printed
  966.      representation of the integer.  This special case exists for
  967.      compatibility with Mocklisp, and we don't recommend you take
  968.      advantage of it.  If you want to convert an integer in this way,
  969.      use `format' (*note Formatting Strings::.) or `int-to-string'
  970.      (*note String Conversion::.).
  971.  
  972.           (concat 137)
  973.                => "137"
  974.           (concat 54 321)
  975.                => "54321"
  976.  
  977.      For information about other concatenation functions, see
  978.      `mapconcat' in *Note Mapping Functions::, `vconcat' in *Note
  979.      Vectors::, and `append' in *Note Building Lists::.
  980.  
  981. 
  982. File: elisp,  Node: Text Comparison,  Next: String Conversion,  Prev: Creating Strings,  Up: Strings and Characters
  983.  
  984. Comparison of Characters and Strings
  985. ====================================
  986.  
  987.  -- Function: char-equal CHARACTER1 CHARACTER2
  988.      This function returns `t' if the arguments represent the same
  989.      character, `nil' otherwise.  This is done by comparing two integers
  990.      modulo 256.
  991.  
  992.           (char-equal ?x ?x)
  993.                => t
  994.           (char-to-string (+ 256 ?x))
  995.                => "x"
  996.           (char-equal ?x  (+ 256 ?x))
  997.                => t
  998.  
  999.  -- Function: string= STRING1 STRING2
  1000.      This function returns `t' if the characters of the two strings
  1001.      match exactly; case is significant.
  1002.  
  1003.           (string= "abc" "abc")
  1004.                => t
  1005.           (string= "abc" "ABC")
  1006.                => nil
  1007.           (string= "ab" "ABC")
  1008.                => nil
  1009.  
  1010.  -- Function: string-equal STRING1 STRING2
  1011.      `string-equal' is another name for `string='.
  1012.  
  1013.  -- Function: string< STRING1 STRING2
  1014.      This function compares two strings a character at a time.  First it
  1015.      scans both the strings at once to find the first pair of
  1016.      corresponding characters that do not match.  If the lesser
  1017.      character of those two is the character from STRING1, then STRING1
  1018.      is less, and this function returns `t'.  If the lesser character
  1019.      is the one from STRING2, then STRING1 is greater, and this
  1020.      function returns `nil'.  If the two strings match entirely, the
  1021.      value is `nil'.
  1022.  
  1023.      Pairs of characters are compared by their ASCII codes.  Keep in
  1024.      mind that lower case letters have higher numeric values in the
  1025.      ASCII character set than their upper case counterparts; numbers and
  1026.      many punctuation characters have a lower numeric value than upper
  1027.      case letters.
  1028.  
  1029.           (string< "abc" "abd")
  1030.                => t
  1031.           (string< "abd" "abc")
  1032.                => nil
  1033.           (string< "123" "abc")
  1034.                => t
  1035.  
  1036.      When the strings have different lengths, and they match up to the
  1037.      length of STRING1, then the result is `t'.  If they match up to
  1038.      the length of STRING2, the result is `nil'. A string without any
  1039.      characters in it is the smallest possible string.
  1040.  
  1041.           (string< "" "abc")
  1042.                => t
  1043.           (string< "ab" "abc")
  1044.                => t
  1045.           (string< "abc" "")
  1046.                => nil
  1047.           (string< "abc" "ab")
  1048.                => nil
  1049.           (string< "" "")
  1050.                => nil
  1051.  
  1052.  -- Function: string-lessp STRING1 STRING2
  1053.      `string-lessp' is another name for `string<'.
  1054.  
  1055. 
  1056. File: elisp,  Node: String Conversion,  Next: Formatting Strings,  Prev: Text Comparison,  Up: Strings and Characters
  1057.  
  1058. Conversion of Characters and Strings
  1059. ====================================
  1060.  
  1061.    Characters and strings may be converted into each other and into
  1062. integers.  `format' and `prin1-to-string' (*note Output Functions::.)
  1063. may also be used to convert Lisp objects into strings. 
  1064. `read-from-string' (*note Input Functions::.) may be used to "convert"
  1065. a string representation of a Lisp object into an object.
  1066.  
  1067.    *Note Documentation::, for a description of the functions
  1068. `single-key-description' and `text-char-description', which return a
  1069. string representing the Emacs standard notation of the argument
  1070. character.  These functions are used primarily for printing help
  1071. messages.
  1072.  
  1073.  -- Function: char-to-string CHARACTER
  1074.      This function returns a new string with a length of one character.
  1075.      The value of CHARACTER, modulo 256, is used to initialize the
  1076.      element of the string.
  1077.  
  1078.      This function is similar to `make-string' with an integer argument
  1079.      of 1.  (*Note Creating Strings::.)  This conversion can also be
  1080.      done with `format' using the `%c' format specification. (*Note
  1081.      Formatting Strings::.)
  1082.  
  1083.           (char-to-string ?x)
  1084.                => "x"
  1085.           (char-to-string (+ 256 ?x))
  1086.                => "x"
  1087.           (make-string 1 ?x)
  1088.                => "x"
  1089.  
  1090.  -- Function: string-to-char STRING
  1091.      This function returns the first character in STRING.  If the
  1092.      string is empty, the function returns 0.  The value is also 0 when
  1093.      the first character of STRING is the null character, ASCII code 0.
  1094.  
  1095.           (string-to-char "ABC")
  1096.                => 65
  1097.           (string-to-char "xyz")
  1098.                => 120
  1099.           (string-to-char "")
  1100.                => 0
  1101.           (string-to-char "\000")
  1102.                => 0
  1103.  
  1104.      This function may be eliminated in version 19 if it does not seem
  1105.      useful enough to retain.
  1106.  
  1107.  -- Function: int-to-string INTEGER
  1108.      This function returns a string consisting of the digits of
  1109.      INTEGER, base ten.  When passed a positive integer as an argument,
  1110.      this function returns an unsigned string.  When passed a negative
  1111.      integer, the function returns a string with a leading minus sign.
  1112.  
  1113.           (int-to-string 256)
  1114.                => "256"
  1115.           (int-to-string -23)
  1116.                => "-23"
  1117.  
  1118.      See also the function `format' in *Note Formatting Strings::.
  1119.  
  1120.  -- Function: string-to-int STRING
  1121.      This function returns the integer value of the characters in
  1122.      STRING, read as a number in base ten.
  1123.  
  1124.      The string is read starting from (and including) the first
  1125.      character, and it is read until a non-digit is encountered.  If
  1126.      the first character is not a digit or a minus sign, this function
  1127.      returns 0.
  1128.  
  1129.           (string-to-int "256")
  1130.                => 256
  1131.           (string-to-int "25 is a perfect square.")
  1132.                => 25
  1133.           (string-to-int "X256")
  1134.                => 0
  1135.           (string-to-int "-4")
  1136.                => -4
  1137.  
  1138. 
  1139. File: elisp,  Node: Formatting Strings,  Next: Character Case,  Prev: String Conversion,  Up: Strings and Characters
  1140.  
  1141. Formatting Strings
  1142. ==================
  1143.  
  1144.    "Formatting" means constructing a string by substitution of computed
  1145. values at various places in a constant string.  This string controls
  1146. how the other values are printed as well as where they appear; it is
  1147. called a "format string".
  1148.  
  1149.    Formatting is often useful for computing messages to be displayed. 
  1150. In fact, the functions `message' and `error' provide the same
  1151. formatting feature described here; they differ from `format' only in
  1152. how they use the result of formatting.
  1153.  
  1154.  -- Function: format STRING &rest OBJECTS
  1155.      This function returns a new string that is made by copying STRING
  1156.      and then replacing any format specification in the copy with
  1157.      encodings of the corresponding OBJECTS.  The arguments OBJECTS are
  1158.      the computed values to be formatted.
  1159.  
  1160.    A format specification is a sequence of characters beginning with a
  1161. `%'.  Thus, if there is a `%d' in STRING, the `format' function
  1162. replaces it with the printed representation of one of the values to be
  1163. formatted (one of the arguments OBJECTS). For example:
  1164.  
  1165.      (format "The value of fill-column is %d." fill-column)
  1166.           => "The value of fill-column is 72."
  1167.  
  1168.    If STRING contains more than one format specification, the format
  1169. specifications are matched in order with successive values from
  1170. OBJECTS.  Thus, the first format specification in STRING is matched
  1171. with the first such value, the second format specification is matched
  1172. with the second such value, and so on.  Any extra format specifications
  1173. (those for which there are no corresponding values) cause unpredictable
  1174. behavior.  Any extra values to be formatted will be ignored.
  1175.  
  1176.    Certain format specifications require values of particular types.
  1177. However, no error is signaled if the value actually supplied fails to
  1178. have the expected type.  Instead, meaningless text is likely to be
  1179. output.
  1180.  
  1181.    Here is a table of the characters that can follow `%' to make up a
  1182. format specification:
  1183.  
  1184. `s'
  1185.      Replace the specification with the printed representation of the
  1186.      object. If there is no corresponding object, the empty string is
  1187.      used.
  1188.  
  1189. `o'
  1190.      Replace the specification with the base-eight representation of an
  1191.      integer.
  1192.  
  1193. `d'
  1194.      Replace the specification with the base-ten representation of an
  1195.      integer.
  1196.  
  1197. `x'
  1198.      Replace the specification with the base-sixteen representation of
  1199.      an integer.
  1200.  
  1201. `c'
  1202.      Replace the specification with the character which is the value
  1203.      given.
  1204.  
  1205. `%'
  1206.      A single `%' is placed in the string.  This format specification is
  1207.      unusual in that it does not use a value.  For example, `(format "%%
  1208.      %d" 30)' returns `"% 30"'.
  1209.  
  1210.    Any other format character results in an `Invalid format operation'
  1211. error.
  1212.  
  1213.    Here are several examples:
  1214.  
  1215.      (format "The name of this buffer is %s." (buffer-name))
  1216.           => "The name of this buffer is strings.texi."
  1217.      
  1218.      (format "The buffer object prints as %s." (current-buffer))
  1219.           => "The buffer object prints as #<buffer strings.texi>."
  1220.      
  1221.      (format "The octal value of 18 is %o, and the hex value is %x."
  1222.              18 18)
  1223.           => "The octal value of 18 is 22, and the hex value is 12."
  1224.  
  1225.    All the specification characters allow an optional numeric prefix
  1226. between the `%' and the character.  The optional numeric prefix defines
  1227. the minimum width for the object.  If the printed representation of the
  1228. object contains fewer characters than this, then it is padded. The
  1229. padding is on the left if the prefix is positive (or starts with zero)
  1230. and on the right if the prefix is negative.  The padding character is
  1231. normally a space, but if the numeric prefix starts with a zero, zeros
  1232. are used for padding.
  1233.  
  1234.      (format "%06d will be padded on the left with zeros" 123)
  1235.           => "000123 will be padded on the left with zeros"
  1236.      
  1237.      (format "%-6d will be padded on the right" 123)
  1238.           => "123    will be padded on the right"
  1239.  
  1240.    No matter what the prefix, nothing in the printed representation will
  1241. be truncated.  This allows the programmer to specify minimum spacing
  1242. without knowing how many characters there are in the object's printed
  1243. representation.
  1244.  
  1245.    In the following three examples, `%7s' specifies a minimum width of
  1246. 7.  In the first case, the string inserted in place of `%7s' has only 3
  1247. letters, so 4 blank spaces are inserted for padding.  In the second
  1248. case, the string `"specification"' is 13 letters wide but is not
  1249. truncated.  In the third case, the padding is on the right.  (This does
  1250. not work in version 18, but does work in version 19.)
  1251.  
  1252.      (format "The word `%7s' actually has %d letters in it." "foo"
  1253.              (length "foo"))
  1254.           => "The word `    foo' actually has 3 letters in it."
  1255.      
  1256.      (format "The word `%7s' actually has %d letters in it."
  1257.              "specification"
  1258.              (length "specification"))
  1259.           => "The word `specification' actually has 13 letters in it."
  1260.      
  1261.      (format "The word `%-7s' actually has %d letters in it." "foo"
  1262.              (length "foo"))
  1263.           => "The word `foo    ' actually has 3 letters in it."
  1264.      ;; `%-7s' fails to work in version 18, but does work in version 19.
  1265.      ;; In version 18, padding is not inserted.
  1266.  
  1267. 
  1268. File: elisp,  Node: Character Case,  Prev: Formatting Strings,  Up: Strings and Characters
  1269.  
  1270. Character Case
  1271. ==============
  1272.  
  1273.    The character case functions change the case of single characters or
  1274. of the contents of strings.  The functions convert only alphabetic
  1275. characters (the letters `A' through `Z' and `a' through `z'); other
  1276. characters are not altered.  The functions do not modify the strings
  1277. that are passed to them as arguments.
  1278.  
  1279.    The examples below use the characters `X' and `x' which have ASCII
  1280. codes 88 and 120 respectively.
  1281.  
  1282.  -- Function: downcase STRING-OR-CHAR
  1283.      This function converts a character or a string to lower case.
  1284.  
  1285.      When the argument to `downcase' is a string, the function creates
  1286.      and returns a new string in which each letter in the argument that
  1287.      is upper case is converted to lower case.  When the argument to
  1288.      `downcase' is a character, `downcase' returns the corresponding
  1289.      lower case character.  This value is an integer.  If the original
  1290.      character is lower case, or is not a letter, then the value equals
  1291.      the original character.
  1292.  
  1293.           (downcase "The cat in the hat")
  1294.                => "the cat in the hat"
  1295.           
  1296.           (downcase ?X)
  1297.                => 120
  1298.  
  1299.  -- Function: upcase STRING-OR-CHAR
  1300.      This function converts a character or a string to upper case.
  1301.  
  1302.      When the argument to `upcase' is a string, the function creates
  1303.      and returns a new string in which each letter in the argument that
  1304.      is lower case is converted to upper case.
  1305.  
  1306.      When the argument to `upcase' is a character, `upcase' returns the
  1307.      corresponding upper case character.  This value is an integer. If
  1308.      the original character is upper case, or is not a letter, then the
  1309.      value equals the original character.
  1310.  
  1311.           (upcase "The cat in the hat")
  1312.                => "THE CAT IN THE HAT"
  1313.           
  1314.           (upcase ?x)
  1315.                => 88
  1316.  
  1317.  -- Function: capitalize STRING-OR-CHAR
  1318.      This function capitalizes strings or characters.  If
  1319.      STRING-OR-CHAR is a string, the function creates and returns a new
  1320.      string, whose contents are a copy of STRING-OR-CHAR in which each
  1321.      word has been capitalized.  This means that the first character of
  1322.      each word is converted to upper case, and the rest are converted
  1323.      to lower case.
  1324.  
  1325.      The definition of a word is any sequence of consecutive characters
  1326.      that are assigned to the word constituent category in the current
  1327.      syntax table (*Note Syntax Class Table::).
  1328.  
  1329.      When the argument to `capitalize' is a character, `capitalize' has
  1330.      the same result as `upcase'.
  1331.  
  1332.           (capitalize "The cat in the hat")
  1333.                => "The Cat In The Hat"
  1334.           
  1335.           (capitalize "THE 77TH-HATTED CAT")
  1336.                => "The 77th-Hatted Cat"
  1337.           
  1338.           (capitalize ?x)
  1339.                => 88
  1340.  
  1341.