home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i04 < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  51.0 KB  |  1,384 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: Lists,  Next: Sequences Arrays Vectors,  Prev: Strings and Characters,  Up: Top
  30.  
  31. Lists
  32. *****
  33.  
  34.    A "list" represents a sequence of zero or more elements (which may
  35. be any Lisp objects).  The important difference between lists and
  36. vectors is that two or more lists can share part of their structure; in
  37. addition, you can insert or delete elements in a list without copying
  38. the whole list.
  39.  
  40. * Menu:
  41.  
  42. * Cons Cells::          How lists are made out of cons cells.
  43. * Lists as Boxes::                 Graphical notation to explain lists.
  44. * List-related Predicates::        Is this object a list?  Comparing two lists.
  45. * List Elements::       Extracting the pieces of a list.
  46. * Building Lists::      Creating list structure.
  47. * Modifying Lists::     Storing new pieces into an existing list.
  48. * Sets And Lists::      A list can represent a finite mathematical set.
  49. * Association Lists::   A list can represent a finite relation or mapping.
  50.  
  51. 
  52. File: elisp,  Node: Cons Cells,  Next: Lists as Boxes,  Prev: Lists,  Up: Lists
  53.  
  54. Lists and Cons Cells
  55. ====================
  56.  
  57.    Lists in Lisp are not a primitive data type; they are built up from
  58. "cons cells".  A cons cell is a data object which represents an ordered
  59. pair.  It records two Lisp objects, one labeled as the CAR, and the
  60. other labeled as the CDR.  (These names are traditional.)
  61.  
  62.    A list is made by chaining cons cells together, one cons cell per
  63. element.  By convention, the CARs of the cons cells are the elements of
  64. the list, and the CDRs are used to chain the list: the CDR of each cons
  65. cell is the following cons cell.  The CDR of the last cons cell is
  66. `nil'.  This asymmetry between the CAR and the CDR is entirely a matter
  67. of convention; at the level of cons cells, the CAR and CDR slots have
  68. the same characteristics.
  69.  
  70.    The symbol `nil' is considered a list as well as a symbol; it is the
  71. list with no elements.  Therefore, the CDR of any nonempty list L is a
  72. list containing all the elements of L except the first.  For
  73. convenience, the symbol `nil' is considered to have `nil' as its CDR
  74. (and also as its CAR).
  75.  
  76. 
  77. File: elisp,  Node: Lists as Boxes,  Next: List-related Predicates,  Prev: Cons Cells,  Up: Lists
  78.  
  79. Lists as Linked Pairs of Boxes
  80. ==============================
  81.  
  82.    A cons cell can be illustrated as a pair of boxes.  The first box
  83. represents the CAR and the second box represents the CDR. Here is an
  84. illustration of the two-element list, `(tulip lily)', made from two
  85. cons cells:
  86.  
  87.       ---------------         ---------------
  88.      |car    |cdr    |       |car    |cdr    |
  89.      | tulip |   o---------->| lily  |  nil  |
  90.      |       |       |       |       |       |
  91.       ---------------         ---------------
  92.  
  93.    Each pair of boxes represents a cons cell.  Each box "refers to",
  94. "points to" or "contains" a Lisp object.  (These terms are synonymous.)
  95.  The first box, which is the CAR of the first cons cell, contains the
  96. symbol `tulip'.  The arrow from the CDR of the first cons cell to the
  97. second cons cell indicates that the CDR of the first cons cell points
  98. to the second cons cell.
  99.  
  100.    The same list can be illustrated in a different sort of box notation
  101. like this:
  102.  
  103.          ___ ___      ___ ___
  104.         |___|___|--> |___|___|--> nil
  105.           |            |
  106.           |            |
  107.            --> tulip    --> lily
  108.  
  109.    Here is a more complex illustration, this time of the three-element
  110. list, `((pine needles) oak maple)', the first element of which is a
  111. two-element list:
  112.  
  113.          ___ ___      ___ ___      ___ ___
  114.         |___|___|--> |___|___|--> |___|___|--> nil
  115.           |            |            |
  116.           |            |            |
  117.           |             --> oak      --> maple
  118.           |
  119.           |     ___ ___      ___ ___
  120.            --> |___|___|--> |___|___|--> nil
  121.                  |            |
  122.                  |            |
  123.                   --> pine     --> needles
  124.  
  125.    The same list is represented in the first box notation like this:
  126.  
  127.       ---------------         ---------------         ---------------
  128.      |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  129.      |   o   |   o---------->|  oak  |   o---------->| maple |  nil  |
  130.      |   |   |       |       |       |       |       |       |       |
  131.       -- | ----------         ---------------         ---------------
  132.          |
  133.          |
  134.          |        ---------------         -----------------
  135.          |       |car    |cdr    |       |car      |cdr    |
  136.           ------>| pine  |   o---------->| needles |  nil  |
  137.                  |       |       |       |         |       |
  138.                   ---------------         -----------------
  139.  
  140.    *Note List Type::, for the read and print syntax of lists, and for
  141. more "box and arrow" illustrations of lists.
  142.  
  143. 
  144. File: elisp,  Node: List-related Predicates,  Next: List Elements,  Prev: Lists as Boxes,  Up: Lists
  145.  
  146. Predicates on Lists
  147. ===================
  148.  
  149.    The following predicates test whether a Lisp object is an atom, is a
  150. cons cell or is a list, or whether it is the distinguished object `nil'.
  151. (Many of these tests can be defined in terms of the others, but they are
  152. used so often that it is worth having all of them.)
  153.  
  154.  -- Function: consp OBJECT
  155.      This function returns `t' if OBJECT is a cons cell, `nil'
  156.      otherwise.  `nil' is not a cons cell, although it *is* a list.
  157.  
  158.  -- Function: atom OBJECT
  159.      This function returns `t' if OBJECT is an atom, `nil' otherwise. 
  160.      All objects except cons cells are atoms.  The symbol `nil' is an
  161.      atom and is also a list; it is the only Lisp object which is both.
  162.  
  163.           (atom OBJECT) == (not (consp OBJECT))
  164.  
  165.  -- Function: listp OBJECT
  166.      This function returns `t' if OBJECT is a cons cell or `nil'. 
  167.      Otherwise, it returns `nil'.
  168.  
  169.           (listp '(1))
  170.                => t
  171.           (listp '())
  172.                => t
  173.  
  174.  -- Function: nlistp OBJECT
  175.      This function is the opposite of `listp': it returns `t' if OBJECT
  176.      is not a list.  Otherwise, it returns `nil'.
  177.  
  178.           (listp OBJECT) == (not (nlistp OBJECT))
  179.  
  180.  -- Function: null OBJECT
  181.      This function returns `t' if OBJECT is `nil', and returns `nil'
  182.      otherwise.  This function is identical to `not', but as a matter
  183.      of clarity we use `null' when OBJECT is considered a list and
  184.      `not' when it is considered a truth value (see `not' in *Note
  185.      Combining Conditions::).
  186.  
  187.           (null '(1))
  188.                => nil
  189.           (null '())
  190.                => t
  191.  
  192. 
  193. File: elisp,  Node: List Elements,  Next: Building Lists,  Prev: List-related Predicates,  Up: Lists
  194.  
  195. Accessing Elements of Lists
  196. ===========================
  197.  
  198.  -- Function: car CONS-CELL
  199.      This function returns the value pointed to by the first pointer of
  200.      the cons cell CONS-CELL.  Expressed another way, this function
  201.      returns the CAR of CONS-CELL.
  202.  
  203.      As a special case, if CONS-CELL is `nil', then `car' is defined to
  204.      return `nil'; therefore, any list is a valid argument for `car'. 
  205.      An error is signaled if the argument is not a cons cell or `nil'.
  206.  
  207.           (car '(a b c))
  208.                => a
  209.           (car '())
  210.                => nil
  211.  
  212.  -- Function: cdr CONS-CELL
  213.      This function returns the value pointed to by the second pointer of
  214.      the cons cell CONS-CELL.  Expressed another way, this function
  215.      returns the CDR of CONS-CELL.
  216.  
  217.      As a special case, if CONS-CELL is `nil', then `cdr' is defined to
  218.      return `nil'; therefore, any list is a valid argument for `cdr'. 
  219.      An error is signaled if the argument is not a cons cell or `nil'.
  220.  
  221.           (cdr '(a b c))
  222.                => (b c)
  223.           (cdr '())
  224.                => nil
  225.  
  226.  -- Function: car-safe OBJECT
  227.      This function lets you take the CAR of a cons cell while avoiding
  228.      errors for other data types.  It returns the CAR of OBJECT if
  229.      OBJECT is a cons cell, `nil' otherwise.  This is in contrast to
  230.      `car', which signals an error if OBJECT is not a list.
  231.  
  232.           (car-safe OBJECT)
  233.           ==
  234.           (let ((x OBJECT))
  235.             (if (consp x)
  236.                 (car x)
  237.               nil))
  238.  
  239.  -- Function: cdr-safe OBJECT
  240.      This function lets you take the CDR of a cons cell while avoiding
  241.      errors for other data types.  It returns the CDR of OBJECT if
  242.      OBJECT is a cons cell, `nil' otherwise. This is in contrast to
  243.      `cdr', which signals an error if OBJECT is not a list.
  244.  
  245.           (cdr-safe OBJECT)
  246.           ==
  247.           (let ((x OBJECT))
  248.             (if (consp x)
  249.                 (cdr x)
  250.               nil))
  251.  
  252.  -- Function: nth N LIST
  253.      This function returns the Nth element of LIST.  Elements are
  254.      numbered starting with zero, so the CAR of LIST is element number
  255.      zero.  If the length of LIST is N or less, the value is `nil'.
  256.  
  257.      If N is less than zero, then the first element is returned.
  258.  
  259.           (nth 2 '(1 2 3 4))
  260.                => 3
  261.           (nth 10 '(1 2 3 4))
  262.                => nil
  263.           (nth -3 '(1 2 3 4))
  264.                => 1
  265.           
  266.           (nth n x) == (car (nthcdr n x))
  267.  
  268.  -- Function: nthcdr N LIST
  269.      This function returns the Nth cdr of LIST.  In other words, it
  270.      removes the first N links of LIST and returns what follows.
  271.  
  272.      If N is less than or equal to zero, then all of LIST is returned. 
  273.      If the length of LIST is N or less, the value is `nil'.
  274.  
  275.           (nthcdr 1 '(1 2 3 4))
  276.                => (2 3 4)
  277.           (nthcdr 10 '(1 2 3 4))
  278.                => nil
  279.           (nthcdr -3 '(1 2 3 4))
  280.                => (1 2 3 4)
  281.  
  282. 
  283. File: elisp,  Node: Building Lists,  Next: Modifying Lists,  Prev: List Elements,  Up: Lists
  284.  
  285. Building Cons Cells and Lists
  286. =============================
  287.  
  288.    Many functions build lists, as lists reside at the very heart of
  289. Lisp. `cons' is the fundamental list-building function; however, it is
  290. interesting to note that `list' is used more times in the source code
  291. for Emacs than `cons'.
  292.  
  293.  -- Function: cons OBJECT1 OBJECT2
  294.      This function is the fundamental function used to build new list
  295.      structure.  It creates a new cons cell, making OBJECT1 the CAR,
  296.      and OBJECT2 the CDR.  It then returns the new cons cell.  The
  297.      arguments OBJECT1 and OBJECT2 may be any Lisp objects, but most
  298.      often OBJECT2 is a list.
  299.  
  300.           (cons 1 '(2))
  301.                => (1 2)
  302.           (cons 1 '())
  303.                => (1)
  304.           (cons 1 2)
  305.                => (1 . 2)
  306.  
  307.      `cons' is often used to add a single element to the front of a
  308.      list.  This is called "consing the element onto the list".  For
  309.      example:
  310.  
  311.           (setq list (cons newelt list))
  312.  
  313.  -- Function: list &rest OBJECTS
  314.      This function creates a list with OBJECTS as its elements.  The
  315.      resulting list is always `nil'-terminated.  If no OBJECTS are
  316.      given, the empty list is returned.
  317.  
  318.           (list 1 2 3 4 5)
  319.                => (1 2 3 4 5)
  320.           (list 1 2 '(3 4 5) 'foo)
  321.                => (1 2 (3 4 5) foo)
  322.           (list)
  323.                => nil
  324.  
  325.  -- Function: make-list LENGTH OBJECT
  326.      This function creates a list of length LENGTH, in which all the
  327.      elements have the identical value OBJECT.  Compare `make-list'
  328.      with `make-string' (*note Creating Strings::.).
  329.  
  330.           (make-list 3 'pigs)
  331.                => (pigs pigs pigs)
  332.           (make-list 0 'pigs)
  333.                => nil
  334.  
  335.  -- Function: append &rest SEQUENCES
  336.      This function returns a list containing all the elements of
  337.      SEQUENCES.  The SEQUENCES may be lists, vectors, strings, or
  338.      integers.  All arguments except the last one are copied, so none
  339.      of them are altered.
  340.  
  341.      The final argument to `append' may be any object but it is
  342.      typically a list.  The final argument is not copied or converted;
  343.      it becomes part of the structure of the new list.
  344.  
  345.      Here is an example:
  346.  
  347.           (setq trees '(pine oak))
  348.                => (pine oak)
  349.           (setq more-trees (append '(maple birch) trees))
  350.                => (maple birch pine oak)
  351.           
  352.           trees
  353.                => (pine oak)
  354.           more-trees
  355.                => (maple birch pine oak)
  356.           (eq trees (cdr (cdr more-trees)))
  357.                => t
  358.  
  359.      You can see what happens by looking at a box diagram.  The variable
  360.      `trees' is set to the list `(pine oak)' and then the variable
  361.      `more-trees' is set to the list `(maple birch pine oak)'. However,
  362.      the variable `trees' continues to refer to the original list:
  363.  
  364.           more-trees                trees
  365.           |                           |
  366.           |     ___ ___      ___ ___   -> ___ ___      ___ ___
  367.            --> |___|___|--> |___|___|--> |___|___|--> |___|___|--> nil
  368.                  |            |            |            |
  369.                  |            |            |            |
  370.                   --> maple    -->birch     --> pine     --> oak
  371.  
  372.      An empty sequence contributes nothing to the value returned by
  373.      `append'.  As a consequence of this, a final `nil' argument forces
  374.      a copy of the previous argument.
  375.  
  376.           trees
  377.                => (pine oak)
  378.           (setq wood (append trees ()))
  379.                => (pine oak)
  380.           wood
  381.                => (pine oak)
  382.           (eq wood trees)
  383.                => nil
  384.  
  385.      This once was the standard way to copy a list, before the function
  386.      `copy-sequence' was invented.  *Note Sequences Arrays Vectors::.
  387.  
  388.      With the help of `apply', we can append all the lists in a list of
  389.      lists:
  390.  
  391.           (apply 'append '((a b c) nil (x y z) nil))
  392.                => (a b c x y z)
  393.  
  394.      If no SEQUENCES are given, `nil' is returned:
  395.  
  396.           (append)
  397.                => nil
  398.  
  399.      In the special case where one of the SEQUENCES is an integer (not
  400.      a sequence of integers), it is first converted to a string of
  401.      digits making up the decimal print representation of the integer. 
  402.      This special case exists for compatibility with Mocklisp, and we
  403.      don't recommend you take advantage of it.  If you want to convert
  404.      an integer in this way, use `format' (*note Formatting Strings::.)
  405.      or `int-to-string' (*note String Conversion::.).
  406.  
  407.           (setq trees '(pine oak))
  408.                => (pine oak)
  409.           (char-to-string ?\054)
  410.                => "6"
  411.           (setq longer-list (append trees 6 '(spruce)))
  412.                => (pine oak 54 spruce)
  413.           (setq x-list (append trees 6 6))
  414.                => (pine oak 54 . 6)
  415.  
  416.      See `nconc' in *Note Rearrangement::, for another way to join lists
  417.      without copying.
  418.  
  419.  -- Function: reverse LIST
  420.      This function creates a new list whose elements are the elements of
  421.      LIST, but in reverse order.  The original argument LIST is *not*
  422.      altered.
  423.  
  424.           (setq x '(1 2 3 4))
  425.                => (1 2 3 4)
  426.           (reverse x)
  427.                => (4 3 2 1)
  428.           x
  429.                => (1 2 3 4)
  430.  
  431. 
  432. File: elisp,  Node: Modifying Lists,  Next: Sets And Lists,  Prev: Building Lists,  Up: Lists
  433.  
  434. Modifying Existing List Structure
  435. =================================
  436.  
  437.    You can modify the CAR and CDR contents of a cons cell with the
  438. primitives `setcar' and `setcdr'.
  439.  
  440.      Common Lisp note: Common Lisp uses functions `rplaca' and `rplacd'
  441.      to alter list structure; they change structure the same way as
  442.      `setcar' and `setcdr', but the Common Lisp functions return the
  443.      cons cell while `setcar' and `setcdr' return the new CAR or CDR.
  444.  
  445. * Menu:
  446.  
  447. * Setcar::          Replacing an element in a list.
  448. * Setcdr::          Replacing part of the list backbone.
  449.                       This can be used to remove or add elements.
  450. * Rearrangement::   Reordering the elements in a list; combining lists.
  451.  
  452. 
  453. File: elisp,  Node: Setcar,  Next: Setcdr,  Prev: Modifying Lists,  Up: Modifying Lists
  454.  
  455. Altering List Elements with `setcar'
  456. ------------------------------------
  457.  
  458.    Changing the CAR of a cons cell is done with `setcar' and replaces
  459. one element of a list with a different element.
  460.  
  461.  -- Function: setcar CONS OBJECT
  462.      This function stores OBJECT as the new CAR of CONS, replacing its
  463.      previous CAR.  It returns the value OBJECT. For example:
  464.  
  465.           (setq x '(1 2))
  466.                => (1 2)
  467.           (setcar x '4)
  468.                => 4
  469.           x
  470.                => (4 2)
  471.  
  472.    When a cons cell is part of the shared structure of several lists,
  473. storing a new CAR into the cons changes one element of each of these
  474. lists.  Here is an example:
  475.  
  476.      ;; Create two lists that are partly shared.
  477.      (setq x1 '(a b c))
  478.           => (a b c)
  479.      (setq x2 (cons 'z (cdr x1)))
  480.           => (z b c)
  481.      
  482.      ;; Replace the CAR of a shared link.
  483.      (setcar (cdr x1) 'foo)
  484.           => foo
  485.      x1                           ; Both lists are changed.
  486.           => (a foo c)
  487.      x2
  488.           => (z foo c)
  489.      
  490.      ;; Replace the CAR of a link that is not shared.
  491.      (setcar x1 'baz)
  492.           => baz
  493.      x1                           ; Only one list is changed.
  494.           => (baz foo c)
  495.      x2
  496.           => (z foo c)
  497.  
  498.    Here is a graphical depiction of the shared structure of the two
  499. lists X1 and X2, showing why replacing `b' changes them both:
  500.  
  501.              ___ ___        ___ ___      ___ ___
  502.      x1---> |___|___|----> |___|___|--> |___|___|--> nil
  503.               |        -->   |            |
  504.               |       |      |            |
  505.                --> a  |       --> b        --> c
  506.                       |
  507.             ___ ___   |
  508.      x2--> |___|___|--
  509.              |
  510.              |
  511.               --> z
  512.  
  513.    Here is an alternative form of box diagram, showing the same
  514. relationship:
  515.  
  516.      x1:
  517.       ---------------         ---------------         ---------------
  518.      |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  519.      |   a   |   o---------->|   b   |   o---------->|   c   |  nil  |
  520.      |       |       |    -->|       |       |       |       |       |
  521.       ---------------    |    ---------------         ---------------
  522.                          |
  523.      x2:                 |
  524.       ---------------    |
  525.      |car    |cdr    |   |
  526.      |   z   |   o-------
  527.      |       |       |
  528.       ---------------
  529.  
  530. 
  531. File: elisp,  Node: Setcdr,  Next: Rearrangement,  Prev: Setcar,  Up: Modifying Lists
  532.  
  533. Altering the CDR of a List
  534. --------------------------
  535.  
  536.    The lowest-level primitive for modifying a CDR is `setcdr':
  537.  
  538.  -- Function: setcdr CONS OBJECT
  539.      This function stores OBJECT into the cdr of CONS.  The value
  540.      returned is OBJECT, not CONS.
  541.  
  542.    Here is an example of replacing the CDR of a list with a different
  543. list.  All but the first element of the list are removed in favor of a
  544. different sequence of elements.  The first element is unchanged,
  545. because it resides in the CAR of the list, and is not reached via the
  546. CDR.
  547.  
  548.      (setq x '(1 2 3))
  549.           => (1 2 3)
  550.      (setcdr x '(4))
  551.           => (4)
  552.      x
  553.           => (1 4)
  554.  
  555.    You can delete elements from the middle of a list by altering the
  556. CDRs of the cons cells in the list.  For example, here we delete the
  557. second element, `b', from the list `(a b c)', by changing the CDR of
  558. the first cell:
  559.  
  560.      (setq x1 '(a b c))
  561.           => (a b c)
  562.      (setcdr x1 '(c))
  563.           => (c)
  564.      x1
  565.           => (a c)
  566.  
  567.    Here is the result in box notation:
  568.  
  569.                           -----------------------
  570.                          |                       |
  571.       ---------------    |    ---------------    |    ---------------
  572.      |car    |cdr    |   |   |car    |cdr    |    -->|car    |cdr    |
  573.      |   a   |   o-------    |   b   |   o---------->|   c   |  nil  |
  574.      |       |       |       |       |       |       |       |       |
  575.       ---------------         ---------------         ---------------
  576.  
  577. The second cons cell, which previously held the element `b', still
  578. exists and its CAR is still `b', but it no longer forms part of this
  579. list.
  580.  
  581.    It is equally easy to insert a new element by changing CDRs:
  582.  
  583.      (setq x1 '(a b c))
  584.           => (a b c)
  585.      (setcdr x1 (cons 'd (cdr x1)))
  586.           => (d b c)
  587.      x1
  588.           => (a d b c)
  589.  
  590.    Here is this result in box notation:
  591.  
  592.       ---------------         ---------------         ---------------
  593.      |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  594.      |   a   |   o   |    -->|   b   |   o---------->|   c   |  nil  |
  595.      |       |   |   |   |   |       |       |       |       |       |
  596.       ---------- | --    |    ---------------         ---------------
  597.                  |       |
  598.            ------         -------
  599.           |                      |
  600.           |    ---------------   |
  601.           |   |car    |cdr    |  |
  602.            -->|   d   |   o------
  603.               |       |       |
  604.                ---------------
  605.  
  606. 
  607. File: elisp,  Node: Rearrangement,  Prev: Setcdr,  Up: Modifying Lists
  608.  
  609. Functions that Rearrange Lists
  610. ------------------------------
  611.  
  612.    Here are some functions that rearrange lists "destructively" by
  613. modifying the CDRs of their component cons cells.  We call these
  614. functions "destructive" because the original lists passed as arguments
  615. to them are chewed up to produce a new list that is subsequently
  616. returned.
  617.  
  618.  -- Function: nconc &rest LISTS
  619.      This function returns a list containing all the elements of LISTS.
  620.      Unlike `append' (*note Building Lists::.), the LISTS are *not*
  621.      copied.  Instead, the last CDR of each of the LISTS is changed to
  622.      refer to the following list.  The last of the LISTS is not
  623.      altered.  For example:
  624.  
  625.           (setq x '(1 2 3))
  626.                => (1 2 3)
  627.           (nconc x '(4 5))
  628.                => (1 2 3 4 5)
  629.           x
  630.                => (1 2 3 4 5)
  631.  
  632.      Since the last argument of `nconc' is not itself modified, it is
  633.      reasonable to use a constant list, such as `'(4 5)', as is done in
  634.      the above example.  For the same reason, the last argument need
  635.      not be a list:
  636.  
  637.           (setq x '(1 2 3))
  638.                => (1 2 3)
  639.           (nconc x 'z)
  640.                => (1 2 3 . z)
  641.           x
  642.                => (1 2 3 . z)
  643.  
  644.      A common pitfall is to use a quoted constant list as a non-last
  645.      argument to `nconc'.  If you do this, your program will change
  646.      each time you run it!  Here is what happens:
  647.  
  648.           (defun add-foo (x)                ; This function should add
  649.             (nconc '(foo) x))               ; `foo' to the front of its arg.
  650.           
  651.           (symbol-function 'add-foo)
  652.                => (lambda (x) (nconc (quote (foo)) x))
  653.           
  654.           (setq xx (add-foo '(1 2)))        ; It seems to work.
  655.                => (foo 1 2)
  656.           (setq xy (add-foo '(3 4)))        ; What happened?
  657.                => (foo 1 2 3 4)
  658.           (eq xx xy)
  659.                => t
  660.           
  661.           (symbol-function 'add-foo)
  662.                => (lambda (x) (nconc (quote (foo 1 2 3 4) x)))
  663.  
  664.  -- Function: nreverse LIST
  665.      This function reverses the order of the elements of LIST. Unlike
  666.      `reverse', `nreverse' alters its argument destructively by
  667.      reversing the CDRs in the cons cells forming the list.  The cons
  668.      cell which used to be the last one in LIST becomes the first cell
  669.      of the value.
  670.  
  671.      For example:
  672.  
  673.           (setq x '(1 2 3 4))
  674.                => (1 2 3 4)
  675.           x
  676.                => (1 2 3 4)
  677.           (nreverse x)
  678.                => (4 3 2 1)
  679.           ;; The cell that was first is now last.
  680.           x
  681.                => (1)
  682.  
  683.      To avoid confusion, we usually store the result of `nreverse' back
  684.      in the same variable which held the original list:
  685.  
  686.           (setq x (nreverse x))
  687.  
  688.      Here is the `nreverse' of our favorite example, `(a b c)',
  689.      presented graphically:
  690.  
  691.           Original list head:                                 Reversed list:
  692.            ---------------         ---------------         ---------------
  693.           |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  694.           |   a   |  nil  |<--    |   b   |   o   |<--    |   c   |   o   |
  695.           |       |       |   |   |       |   |   |   |   |       |   |   |
  696.            ---------------    |    ---------- | --    |    ---------- | --
  697.                               |               |       |               |
  698.                                ---------------         ---------------
  699.  
  700.  -- Function: sort LIST PREDICATE
  701.      This function sorts LIST stably, though destructively, and returns
  702.      the sorted list.  It compares elements using PREDICATE.  A stable
  703.      sort is one in which elements with equal sort keys maintain their
  704.      relative order before and after the sort.  Stability is important
  705.      when successive sorts are used to order elements according to
  706.      different criteria.
  707.  
  708.      The argument PREDICATE must be a function that accepts two
  709.      arguments.  It is called with two elements of LIST.  To get an
  710.      increasing order sort, the PREDICATE should return `t' if the
  711.      first element is "less than" the second, or `nil' if not.
  712.  
  713.      The destructive aspect of `sort' is that it rearranges the cons
  714.      cells forming LIST by changing CDRs.  A nondestructive sort
  715.      function would create new cons cells to store the elements in their
  716.      sorted order.  If you wish to sort a list without destroying the
  717.      original, copy it first with `copy-sequence'.
  718.  
  719.      The CARs of the cons cells are not changed; the cons cell that
  720.      originally contained the element `a' in LIST still has `a' in its
  721.      CAR after sorting, but it now appears in a different position in
  722.      the list due to the change of CDRs.  For example:
  723.  
  724.           (setq nums '(1 3 2 6 5 4 0))
  725.                => (1 3 2 6 5 4 0)
  726.           (sort nums '<)
  727.                => (0 1 2 3 4 5 6)
  728.           nums
  729.                => (1 2 3 4 5 6)
  730.  
  731.      Note that the list in `nums' no longer contains 0; this is the same
  732.      cons cell that it was before, but it is no longer the first one in
  733.      the list.  Don't assume a variable that formerly held the argument
  734.      now holds the entire sorted list!  Instead, save the result of
  735.      `sort' and use that.  Most often we store the result back into the
  736.      variable that held the original list:
  737.  
  738.           (setq nums (sort nums '<))
  739.  
  740.      *Note Sorting::, for more functions that perform sorting. See
  741.      `documentation' in *Note Accessing Documentation::, for a useful
  742.      example of `sort'.
  743.  
  744.    See `delq', in *Note Sets And Lists::, for another function that
  745. modifies cons cells.
  746.  
  747. 
  748. File: elisp,  Node: Sets And Lists,  Next: Association Lists,  Prev: Modifying Lists,  Up: Lists
  749.  
  750. Using Lists as Sets
  751. ===================
  752.  
  753.    A list can represent an unordered mathematical set--simply consider a
  754. value an element of a set if it appears in the list, and ignore the
  755. order of the list.  To form the union of two sets, use `append' (as
  756. long as you don't mind having duplicate elements).  Two other useful
  757. functions for sets are `memq' and `delq'.
  758.  
  759.      Common Lisp note: Common Lisp has functions `union' (which avoids
  760.      duplicate elements) and `intersection' for set operations, but GNU
  761.      Emacs Lisp does not have them.  You can write them in Lisp if you
  762.      wish.
  763.  
  764.  -- Function: memq OBJECT LIST
  765.      This function tests to see whether OBJECT is a member of LIST.  If
  766.      it is, `memq' returns a list starting with the first occurrence of
  767.      OBJECT.  Otherwise, it returns `nil'. The letter `q' in `memq'
  768.      says that it uses `eq' to compare OBJECT against the elements of
  769.      the list.  For example:
  770.  
  771.           (memq 2 '(1 2 3 2 1))
  772.                => (2 3 2 1)
  773.           (memq '(2) '((1) (2)))   ; `(2)' and `(2)' are not `eq'.
  774.                => nil
  775.  
  776.  -- Function: delq OBJECT LIST
  777.      This function removes all elements `eq' to OBJECT from LIST.
  778.  
  779.      Elements at the front of the list are removed (when necessary)
  780.      simply by advancing down the list and returning a sublist that
  781.      starts after those elements:
  782.  
  783.           (delq 'a '(a b c))
  784.           ==
  785.           (cdr '(a b c))
  786.  
  787.      When an element to be deleted appears in the middle of the list,
  788.      removing it involves changing the CDRs (*note Setcdr::.).
  789.  
  790.           (setq sample-list '(1 2 3 (4)))
  791.                => (1 2 3 (4))
  792.           (delq 1 sample-list)
  793.                => (2 3 (4))
  794.           sample-list
  795.                => (1 2 3 (4))
  796.           (delq 2 sample-list)
  797.                => (1 3 (4))
  798.           sample-list
  799.                => (1 3 (4))
  800.  
  801.      Note that `(delq 2 sample-list)' removes the second element of
  802.      `sample-list', but `(delq 1 sample-list)' does not remove the
  803.      first element--it just returns a shorter list.  Don't assume that a
  804.      variable which formerly held the argument LIST now has fewer
  805.      elements, or that it still holds the original list!  Instead, save
  806.      the result of `delq' and use that.  Most often we store the result
  807.      back into the variable that held the original list:
  808.  
  809.           (setq flowers (delq 'rose flowers))
  810.  
  811.      In the following example, the `(4)' that `delq' attempts to match
  812.      and the `(4)' in the `sample-list' are not `eq':
  813.  
  814.           (delq '(4) sample-list)
  815.                => (1 3 (4))
  816.  
  817. 
  818. File: elisp,  Node: Association Lists,  Prev: Sets And Lists,  Up: Lists
  819.  
  820. Association Lists
  821. =================
  822.  
  823.    An "association list", or "alist" for short, records a mapping from
  824. keys to values.  It is a list of cons cells called "associations": the
  825. CAR of each cell is the "key", and the CDR is the "associated value". 
  826. (This usage of "key" is not related to the term "key sequence"; it
  827. means any object which can be looked up in a table.)
  828.  
  829.    Here is an example of an alist.  The key `pine' is associated with
  830. the value `cones'; the key `oak' is associated with `acorns'; and the
  831. key `maple' is associated with `seeds'.
  832.  
  833.      '((pine . cones)
  834.        (oak . acorns)
  835.        (maple . seeds))
  836.  
  837.    The associated values in an alist may be any Lisp objects; so may the
  838. keys.  For example, in the following alist, the symbol `a' is
  839. associated with the number `1', and the string `"b"' is associated with
  840. the *list* `(2 3)', which is the CDR of the alist element:
  841.  
  842.      ((a . 1) ("b" 2 3))
  843.  
  844.    Sometimes it is better to design an alist to store the associated
  845. value in the CAR of the CDR of the element.  Here is an example:
  846.  
  847.      '((rose red) (lily white) (buttercup yellow)))
  848.  
  849. Here we regard `red' as the value associated with `rose'.  One
  850. advantage of this method is that you can store other related
  851. information--even a list of other items--in the CDR of the CDR.  One
  852. disadvantage is that you cannot use `rassq' (see below) to find the
  853. element containing a given value.  When neither of these considerations
  854. is important, the choice is a matter of taste, as long as you are
  855. consistent about it for any given alist.
  856.  
  857.    Note that the same alist shown above could be regarded as having the
  858. associated value in the CDR of the element; the the value associated
  859. with `rose' would be the list `(red)'.
  860.  
  861.    Association lists are often used to record information that you might
  862. otherwise keep on a stack, since new associations may be added easily to
  863. the front of the list.  When searching an association list for an
  864. association with a given key, the first one found is returned, if there
  865. is more than one.
  866.  
  867.    In Emacs Lisp, it is *not* an error if an element of an association
  868. list is not a cons cell.  The alist search functions simply ignore such
  869. elements.  Many other versions of Lisp signal errors in such cases.
  870.  
  871.    Note that property lists are similar to association lists in several
  872. respects.  A property list behaves like an association list in which
  873. each key can occur only once.  *Note Property Lists::, for a comparison
  874. of property lists and association lists.
  875.  
  876.  -- Function: assoc KEY ALIST
  877.      This function returns the first association for KEY in ALIST.  It
  878.      compares KEY against the alist elements using `equal' (*note
  879.      Equality Predicates::.).  It returns `nil' if no association in
  880.      ALIST has a CAR `equal' to KEY. For example:
  881.  
  882.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  883.                => ((pine . cones) (oak . acorns) (maple . seeds))
  884.           (assoc 'oak trees)
  885.                => (oak . acorns)
  886.           (cdr (assoc 'oak trees))
  887.                => acorns
  888.           (assoc 'birch trees)
  889.                => nil
  890.  
  891.      Here is another example in which the keys and values are not
  892.      symbols:
  893.  
  894.           (setq needles-per-cluster
  895.                 '((2 . ("Austrian Pine" "Red Pine"))
  896.                   (3 . "Pitch Pine")
  897.                   (5 . "White Pine")))
  898.           
  899.           (cdr (assoc 3 needles-per-cluster))
  900.                => "Pitch Pine"
  901.           (cdr (assoc 2 needles-per-cluster))
  902.                => ("Austrian Pine" "Red Pine")
  903.  
  904.  -- Function: assq KEY ALIST
  905.      This function is like `assoc' in that it returns the first
  906.      association for KEY in ALIST, but it makes the comparison using
  907.      `eq' instead of `equal'.  `assq' returns `nil' if no association
  908.      in ALIST has a CAR `eq' to KEY. This function is used more often
  909.      than `assoc', since `eq' is faster than `equal' and most alists
  910.      use symbols as keys. *Note Equality Predicates::.
  911.  
  912.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  913.           
  914.           (assq 'pine trees)
  915.                => (pine . cones)
  916.  
  917.      On the other hand, `assq' is not usually useful in alists where the
  918.      keys may not be symbols:
  919.  
  920.           (setq leaves
  921.                 '(("simple leaves" . oak)
  922.                   ("compound leaves" . horsechestnut)))
  923.           
  924.           (assq "simple leaves" leaves)
  925.                => nil
  926.           (assoc "simple leaves" leaves)
  927.                => ("simple leaves" . oak)
  928.  
  929.  -- Function: rassq ALIST VALUE
  930.      This function returns the first association with value VALUE in
  931.      ALIST.  It returns `nil' if no association in ALIST has a CDR `eq'
  932.      to VALUE.
  933.  
  934.      `rassq' is like `assq' except that the CDR of the ALIST
  935.      associations is tested instead of the CAR.  You can think of this
  936.      as "reverse `assq'", finding the key for a given value.
  937.  
  938.      For example:
  939.  
  940.           (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  941.           
  942.           (rassq 'acorns trees)
  943.                => (oak . acorns)
  944.           (rassq 'spores trees)
  945.                => nil
  946.  
  947.      Note that `rassq' cannot be used to search for a value stored in
  948.      the CAR of the CDR of an element:
  949.  
  950.           (setq colors '((rose red) (lily white) (buttercup yellow)))
  951.           
  952.           (rassq 'white colors)
  953.                => nil
  954.  
  955.      In this case, the CDR of the association `(lily white)' is not the
  956.      symbol `white', but rather the list `(white)'.  This can be seen
  957.      more clearly if the association is written in dotted pair notation:
  958.  
  959.           (lily white) == (lily . (white))
  960.  
  961.  -- Function: copy-alist ALIST
  962.      This function returns a two-level deep copy of ALIST: it creates a
  963.      new copy of each association, so that you can alter the
  964.      associations of the new alist without changing the old one.
  965.  
  966.           (setq needles-per-cluster
  967.                 '((2 . ("Austrian Pine" "Red Pine"))
  968.                   (3 . "Pitch Pine")
  969.                   (5 . "White Pine")))
  970.           =>
  971.           ((2 "Austrian Pine" "Red Pine")
  972.            (3 . "Pitch Pine")
  973.            (5 . "White Pine"))
  974.           
  975.           (setq copy (copy-alist needles-per-cluster))
  976.           =>
  977.           ((2 "Austrian Pine" "Red Pine")
  978.            (3 . "Pitch Pine")
  979.            (5 . "White Pine"))
  980.           
  981.           (eq needles-per-cluster copy)
  982.                => nil
  983.           (equal needles-per-cluster copy)
  984.                => t
  985.           (eq (car needles-per-cluster) (car copy))
  986.                => nil
  987.           (cdr (car (cdr needles-per-cluster)))
  988.                => "Pitch Pine"
  989.           (eq (cdr (car (cdr needles-per-cluster)))
  990.               (cdr (car (cdr copy))))
  991.                => t
  992.  
  993. 
  994. File: elisp,  Node: Sequences Arrays Vectors,  Next: Symbols,  Prev: Lists,  Up: Top
  995.  
  996. Sequences, Arrays, and Vectors
  997. ******************************
  998.  
  999.    Recall that the "sequence" type is the union of three other Lisp
  1000. types: lists, vectors, and strings.  In other words, any list is a
  1001. sequence, any vector is a sequence, and any string is a sequence.  The
  1002. common property that all sequences have is that each is an ordered
  1003. collection of elements.
  1004.  
  1005.    An "array" is a single primitive object directly containing all its
  1006. elements.  Therefore, all the elements are accessible in constant time.
  1007.  The length of an existing array cannot be changed.  Both strings and
  1008. vectors are arrays.  A list is a sequence of elements, but it is not a
  1009. single primitive object; it is made of cons cells, one cell per
  1010. element.  Therefore, elements farther from the beginning of the list
  1011. take longer to access, but it is possible to add elements to the list or
  1012. remove elements.  The elements of vectors and lists may be any Lisp
  1013. objects.  The elements of strings are all characters.
  1014.  
  1015.    The following diagram shows the relationship between these types:
  1016.  
  1017.                  ___________________________________
  1018.                 |                                   |
  1019.                 |          Sequence                 |
  1020.                 |  ______   ______________________  |
  1021.                 | |      | |                      | |
  1022.                 | | List | |         Array        | |
  1023.                 | |      | |  ________   _______  | |
  1024.                 | |______| | |        | |       | | |
  1025.                 |          | | String | | Vector| | |
  1026.                 |          | |________| |_______| | |
  1027.                 |          |______________________| |
  1028.                 |___________________________________|
  1029.  
  1030.           The Relationship between Sequences, Arrays, and Vectors
  1031.  
  1032.  
  1033. * Menu:
  1034.  
  1035. * Sequence Functions::    Functions that accept any kind of sequence.
  1036. * Arrays::                Characteristics of arrays in Emacs Lisp.
  1037. * Array Functions::       Functions specifically for arrays.
  1038. * Vectors::               Functions specifically for vectors.
  1039.  
  1040. 
  1041. File: elisp,  Node: Sequence Functions,  Next: Arrays,  Prev: Sequences Arrays Vectors,  Up: Sequences Arrays Vectors
  1042.  
  1043. Sequences
  1044. =========
  1045.  
  1046.    In Emacs Lisp, a "sequence" is either a list, a vector or a string. 
  1047. The common property that all sequences have is that each is an ordered
  1048. collection of elements.  This section describes functions that accept
  1049. any kind of sequence.
  1050.  
  1051.  -- Function: sequencep OBJECT
  1052.      Returns `t' if OBJECT is a list, vector, or string, `nil'
  1053.      otherwise.
  1054.  
  1055.  -- Function: copy-sequence SEQUENCE
  1056.      Returns a copy of SEQUENCE.  The copy is the same type of object
  1057.      as the original sequence, and it has the same elements in the same
  1058.      order.
  1059.  
  1060.      Storing a new element into the copy does not affect the original
  1061.      SEQUENCE, and vice versa.  However, the elements of the new
  1062.      sequence are not copies; they are identical (`eq') to the elements
  1063.      of the original.  Therefore, changes made within these elements, as
  1064.      found via the copied sequence, are also visible in the original
  1065.      sequence.
  1066.  
  1067.      See also `append' in *Note Building Lists::, `concat' in *Note
  1068.      Creating Strings::, and `vconcat' in *Note Vectors::, for others
  1069.      ways to copy sequences.
  1070.  
  1071.           (setq bar '(1 2))
  1072.                => (1 2)
  1073.           (setq x (vector 'foo bar))
  1074.                => [foo (1 2)]
  1075.           (setq y (copy-sequence x))
  1076.                => [foo (1 2)]
  1077.           
  1078.           (eq x y)
  1079.                => nil
  1080.           (equal x y)
  1081.                => t
  1082.           (eq (elt x 1) (elt y 1))
  1083.                => t
  1084.           
  1085.           ;; Replacing an element of one sequence.
  1086.           (aset x 0 'quux)
  1087.           x => [quux (1 2)]
  1088.           y => [foo (1 2)]
  1089.           
  1090.           ;; Modifying the inside of a shared element.
  1091.           (setcar (aref x 1) 69)
  1092.           x => [quux (69 2)]
  1093.           y => [foo (69 2)]
  1094.  
  1095.  -- Function: length SEQUENCE
  1096.      Returns the number of elements in SEQUENCE.  If SEQUENCE is a cons
  1097.      cell that is not a list (because the final CDR is not `nil'), a
  1098.      `wrong-type-argument' error is signaled.
  1099.  
  1100.           (length '(1 2 3))
  1101.               => 3
  1102.           (length nil)
  1103.               => 0
  1104.           (length "foobar")
  1105.               => 6
  1106.           (length [1 2 3])
  1107.               => 3
  1108.  
  1109.  -- Function: elt SEQUENCE INDEX
  1110.      This function returns the element of SEQUENCE indexed by INDEX. 
  1111.      Legitimate values of INDEX are integers ranging from 0 up to one
  1112.      less than the length of SEQUENCE; other values produce an
  1113.      `args-out-of-range' error.
  1114.  
  1115.           (elt [1 2 3 4] 2)
  1116.                => 3
  1117.           (elt '(1 2 3 4) 2)
  1118.                => 3
  1119.           (char-to-string (elt "1234" 2))
  1120.                => "3"
  1121.           (elt [1 2 3 4] 4)
  1122.                error-->Args out of range: [1 2 3 4], 4
  1123.           (elt [1 2 3 4] -1)
  1124.                error-->Args out of range: [1 2 3 4], -1
  1125.  
  1126.      This function duplicates `aref' (*note Array Functions::.) and
  1127.      `nth' (*note List Elements::.), except that it works for any kind
  1128.      of sequence.
  1129.  
  1130. 
  1131. File: elisp,  Node: Arrays,  Next: Array Functions,  Prev: Sequence Functions,  Up: Sequences Arrays Vectors
  1132.  
  1133. Arrays
  1134. ======
  1135.  
  1136.    An "array" object refers directly to a number of other Lisp objects,
  1137. called the elements of the array.  Any element of an array may be
  1138. accessed in constant time.  In contrast, an element of a list requires
  1139. access time that is proportional to the position of the element in the
  1140. list.
  1141.  
  1142.    When you create an array, you must specify how many elements it has.
  1143. The amount of space allocated depends on the number of elements.
  1144. Therefore, it is impossible to change the size of an array once it is
  1145. created.  You cannot add or remove elements.  However, you can replace
  1146. an element with a different value.
  1147.  
  1148.    Emacs defines two types of array, both of which are one-dimensional:
  1149. "strings" and "vectors".  A vector is a general array; its elements can
  1150. be any Lisp objects.  A string is a specialized array; its elements
  1151. must be characters (i.e., integers between 0 and 255).  Each type of
  1152. array has its own read syntax.  *Note String Type::, and *Note Vector
  1153. Type::.
  1154.  
  1155.    Both kinds of arrays share these characteristics:
  1156.  
  1157.    * The first element of an array has index zero, the second element
  1158.      has index 1, and so on.  This is called "zero-origin" indexing. 
  1159.      For example, an array of four elements has indices 0, 1, 2, and 3.
  1160.  
  1161.    * The elements of an array may be referenced or changed with the
  1162.      functions `aref' and `aset', respectively (*note Array
  1163.      Functions::.).
  1164.  
  1165.    In principle, if you wish to have an array of characters, you could
  1166. use either a string or a vector.  In practice, we always choose strings
  1167. for such applications, for three reasons:
  1168.  
  1169.    * They occupy one-fourth the space of a vector of the same elements.
  1170.  
  1171.    * Strings are printed in a way that shows the contents more clearly
  1172.      as characters.
  1173.  
  1174.    * Many of the specialized editing and I/O facilities of Emacs accept
  1175.      only strings.  For example, you cannot insert a vector of
  1176.      characters into a buffer the way you can insert a string.  *Note
  1177.      Strings and Characters::.
  1178.  
  1179. 
  1180. File: elisp,  Node: Array Functions,  Next: Vectors,  Prev: Arrays,  Up: Sequences Arrays Vectors
  1181.  
  1182. Functions that Operate on Arrays
  1183. ================================
  1184.  
  1185.    In this section, we describe the functions that accept both strings
  1186. and vectors.
  1187.  
  1188.  -- Function: arrayp OBJECT
  1189.      This function returns `t' if OBJECT is an array (i.e., either a
  1190.      vector or a string).
  1191.  
  1192.           (arrayp [a])
  1193.           => t
  1194.           (arrayp "asdf")
  1195.           => t
  1196.  
  1197.  -- Function: aref ARRAY INDEX
  1198.      This function returns the INDEXth element of ARRAY.  The first
  1199.      element is at index zero.
  1200.  
  1201.           (setq primes [2 3 5 7 11 13])
  1202.                => [2 3 5 7 11 13]
  1203.           (aref primes 4)
  1204.                => 11
  1205.           (elt primes 4)
  1206.                => 11
  1207.           
  1208.           (aref "abcdefg" 1)
  1209.                => 98           ; `b' is ASCII code 98.
  1210.  
  1211.      See also the function `elt', in *Note Sequence Functions::.
  1212.  
  1213.  -- Function: aset ARRAY INDEX OBJECT
  1214.      This function sets the INDEXth element of ARRAY to be OBJECT.  It
  1215.      returns OBJECT.
  1216.  
  1217.           (setq w [foo bar baz])
  1218.                => [foo bar baz]
  1219.           (aset w 0 'fu)
  1220.                => fu
  1221.           w
  1222.                => [fu bar baz]
  1223.           
  1224.           (setq x "asdfasfd")
  1225.                => "asdfasfd"
  1226.           (aset x 3 ?Z)
  1227.                => 90
  1228.           x
  1229.                => "asdZasfd"
  1230.  
  1231.      If ARRAY is a string and OBJECT is not a character, a
  1232.      `wrong-type-argument' error results.
  1233.  
  1234.  -- Function: fillarray ARRAY OBJECT
  1235.      This function fills the array ARRAY with pointers to OBJECT,
  1236.      replacing any previous values.  It returns ARRAY.
  1237.  
  1238.           (setq a [a b c d e f g])
  1239.                => [a b c d e f g]
  1240.           (fillarray a 0)
  1241.                => [0 0 0 0 0 0 0]
  1242.           a
  1243.                => [0 0 0 0 0 0 0]
  1244.           (setq s "When in the course")
  1245.                => "When in the course"
  1246.           (fillarray s ?-)
  1247.                => "------------------"
  1248.  
  1249.      If ARRAY is a string and OBJECT is not a character, a
  1250.      `wrong-type-argument' error results.
  1251.  
  1252.    The general sequence functions `copy-sequence' and `length' are
  1253. often useful for objects known to be arrays.  *Note Sequence
  1254. Functions::.
  1255.  
  1256. 
  1257. File: elisp,  Node: Vectors,  Prev: Array Functions,  Up: Sequences Arrays Vectors
  1258.  
  1259. Vectors
  1260. =======
  1261.  
  1262.    Arrays in Lisp, like arrays in most languages, are blocks of memory
  1263. whose elements can be accessed in constant time.  A "vector" is a
  1264. general-purpose array; its elements can be any Lisp objects.  (The other
  1265. kind of array provided in Emacs Lisp is the "string", whose elements
  1266. must be characters.)  The main uses of vectors in Emacs are as syntax
  1267. tables (vectors of integers) and keymaps (vectors of commands).  They
  1268. are also used internally as part of the representation of a
  1269. byte-compiled function; if you print such a function, you will see a
  1270. vector in it.
  1271.  
  1272.    The indices of the elements of a vector are numbered starting with
  1273. zero in Emacs Lisp.
  1274.  
  1275.    Vectors are printed with square brackets surrounding the elements in
  1276. their order.  Thus, a vector containing the symbols `a', `b' and `c' is
  1277. printed as `[a b c]'.  You can write vectors in the same way in Lisp
  1278. input.
  1279.  
  1280.    A vector, like a string or a number, is considered a constant for
  1281. evaluation: the result of evaluating it is the same vector.  The
  1282. elements of the vector are not evaluated.  *Note Self-Evaluating
  1283. Forms::.
  1284.  
  1285.    Here are examples of these principles:
  1286.  
  1287.      (setq avector [1 two '(three) "four" [five]])
  1288.           => [1 two (quote (three)) "four" [five]]
  1289.      (eval avector)
  1290.           => [1 two (quote (three)) "four" [five]]
  1291.      (eq avector (eval avector))
  1292.           => t
  1293.  
  1294.    Here are some functions that relate to vectors:
  1295.  
  1296.  -- Function: vectorp OBJECT
  1297.      This function returns `t' if OBJECT is a vector.
  1298.  
  1299.           (vectorp [a])
  1300.                => t
  1301.           (vectorp "asdf")
  1302.                => nil
  1303.  
  1304.  -- Function: vector &rest OBJECTS
  1305.      This function creates and returns a vector whose elements are the
  1306.      arguments, OBJECTS.
  1307.  
  1308.           (vector 'foo 23 [bar baz] "rats")
  1309.                => [foo 23 [bar baz] "rats"]
  1310.           (vector)
  1311.                => []
  1312.  
  1313.  -- Function: make-vector INTEGER OBJECT
  1314.      This function returns a new vector consisting of INTEGER elements,
  1315.      each initialized to OBJECT.
  1316.  
  1317.           (setq sleepy (make-vector 9 'Z))
  1318.                => [Z Z Z Z Z Z Z Z Z]
  1319.  
  1320.  -- Function: vconcat &rest SEQUENCES
  1321.      This function returns a new vector containing all the elements of
  1322.      the SEQUENCES.  The arguments SEQUENCES may be lists, vectors, or
  1323.      strings.  If no SEQUENCES are given, an empty vector is returned.
  1324.  
  1325.      The value is a newly constructed vector that is not `eq' to any
  1326.      existing vector.
  1327.  
  1328.           (setq a (vconcat '(A B C) '(D E F)))
  1329.                => [A B C D E F]
  1330.           (eq a (vconcat a))
  1331.                => nil
  1332.           (vconcat)
  1333.                => []
  1334.           (vconcat [A B C] "aa" '(foo (6 7)))
  1335.                => [A B C 97 97 foo (6 7)]
  1336.  
  1337.      When an argument is an integer (not a sequence of integers), it is
  1338.      converted to a string of digits making up the decimal printed
  1339.      representation of the integer.  This special case exists for
  1340.      compatibility with Mocklisp, and we don't recommend you take
  1341.      advantage of it.  If you want to convert an integer in this way,
  1342.      use `format' (*note Formatting Strings::.) or `int-to-string'
  1343.      (*note String Conversion::.).
  1344.  
  1345.      For other concatenation functions, see `mapconcat' in *Note
  1346.      Mapping Functions::, `concat' in *Note Creating Strings::, and
  1347.      `append' in *Note Building Lists::.
  1348.  
  1349.    The `append' function may be used to convert a vector into a list
  1350. with the same elements (*note Building Lists::.):
  1351.  
  1352.      (setq avector [1 two (quote (three)) "four" [five]])
  1353.           => [1 two (quote (three)) "four" [five]]
  1354.      (append avector nil)
  1355.           => (1 two (quote (three)) "four" [five])
  1356.  
  1357. 
  1358. File: elisp,  Node: Symbols,  Next: Evaluation,  Prev: Sequences Arrays Vectors,  Up: Top
  1359.  
  1360. Symbols
  1361. *******
  1362.  
  1363.    A "symbol" is an object with a unique name.  This chapter describes
  1364. symbols, their components, and how they are created and interned. 
  1365. Property lists are also described.  The uses of symbols as variables
  1366. and as function names are described in separate chapters; see *Note
  1367. Variables::, and *Note Functions::.
  1368.  
  1369.    You may test whether an arbitrary Lisp object is a symbol with
  1370. `symbolp':
  1371.  
  1372.  -- Function: symbolp OBJECT
  1373.      This function returns `t' if OBJECT is a symbol, `nil' otherwise.
  1374.  
  1375. * Menu:
  1376.  
  1377. * Symbol Components::        Symbols have names, values, function definitions
  1378.                                and property lists.
  1379. * Definitions::              A definition says how a symbol will be used.
  1380. * Creating Symbols::         How symbols are kept unique.
  1381. * Property Lists::           Each symbol has a property list
  1382.                                for recording miscellaneous information.
  1383.  
  1384.