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

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