home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-6.z / elisp-6
Encoding:
GNU Info File  |  1994-08-02  |  48.2 KB  |  1,254 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Array Functions,  Next: Vectors,  Prev: Arrays,  Up: Sequences Arrays Vectors
  41.  
  42. Functions that Operate on Arrays
  43. ================================
  44.  
  45.    In this section, we describe the functions that accept both strings
  46. and vectors.
  47.  
  48.  - Function: arrayp OBJECT
  49.      This function returns `t' if OBJECT is an array (i.e., either a
  50.      vector or a string).
  51.  
  52.           (arrayp [a])
  53.           => t
  54.           (arrayp "asdf")
  55.           => t
  56.  
  57.  - Function: aref ARRAY INDEX
  58.      This function returns the INDEXth element of ARRAY.  The first
  59.      element is at index zero.
  60.  
  61.           (setq primes [2 3 5 7 11 13])
  62.                => [2 3 5 7 11 13]
  63.           (aref primes 4)
  64.                => 11
  65.           (elt primes 4)
  66.                => 11
  67.           
  68.           (aref "abcdefg" 1)
  69.                => 98           ; `b' is ASCII code 98.
  70.  
  71.      See also the function `elt', in *Note Sequence Functions::.
  72.  
  73.  - Function: aset ARRAY INDEX OBJECT
  74.      This function sets the INDEXth element of ARRAY to be OBJECT.  It
  75.      returns OBJECT.
  76.  
  77.           (setq w [foo bar baz])
  78.                => [foo bar baz]
  79.           (aset w 0 'fu)
  80.                => fu
  81.           w
  82.                => [fu bar baz]
  83.           
  84.           (setq x "asdfasfd")
  85.                => "asdfasfd"
  86.           (aset x 3 ?Z)
  87.                => 90
  88.           x
  89.                => "asdZasfd"
  90.  
  91.      If ARRAY is a string and OBJECT is not a character, a
  92.      `wrong-type-argument' error results.
  93.  
  94.  - Function: fillarray ARRAY OBJECT
  95.      This function fills the array ARRAY with pointers to OBJECT,
  96.      replacing any previous values.  It returns ARRAY.
  97.  
  98.           (setq a [a b c d e f g])
  99.                => [a b c d e f g]
  100.           (fillarray a 0)
  101.                => [0 0 0 0 0 0 0]
  102.           a
  103.                => [0 0 0 0 0 0 0]
  104.           (setq s "When in the course")
  105.                => "When in the course"
  106.           (fillarray s ?-)
  107.                => "------------------"
  108.  
  109.      If ARRAY is a string and OBJECT is not a character, a
  110.      `wrong-type-argument' error results.
  111.  
  112.    The general sequence functions `copy-sequence' and `length' are
  113. often useful for objects known to be arrays.  *Note Sequence
  114. Functions::.
  115.  
  116. 
  117. File: elisp,  Node: Vectors,  Prev: Array Functions,  Up: Sequences Arrays Vectors
  118.  
  119. Vectors
  120. =======
  121.  
  122.    Arrays in Lisp, like arrays in most languages, are blocks of memory
  123. whose elements can be accessed in constant time.  A "vector" is a
  124. general-purpose array; its elements can be any Lisp objects.  (The other
  125. kind of array provided in Emacs Lisp is the "string", whose elements
  126. must be characters.)  The main uses of vectors in Emacs are as syntax
  127. tables (vectors of integers) and keymaps (vectors of commands).  They
  128. are also used internally as part of the representation of a
  129. byte-compiled function; if you print such a function, you will see a
  130. vector in it.
  131.  
  132.    The indices of the elements of a vector are numbered starting with
  133. zero in Emacs Lisp.
  134.  
  135.    Vectors are printed with square brackets surrounding the elements in
  136. their order.  Thus, a vector containing the symbols `a', `b' and `c' is
  137. printed as `[a b c]'.  You can write vectors in the same way in Lisp
  138. input.
  139.  
  140.    A vector, like a string or a number, is considered a constant for
  141. evaluation: the result of evaluating it is the same vector.  The
  142. elements of the vector are not evaluated.  *Note Self-Evaluating
  143. Forms::.
  144.  
  145.    Here are examples of these principles:
  146.  
  147.      (setq avector [1 two '(three) "four" [five]])
  148.           => [1 two (quote (three)) "four" [five]]
  149.      (eval avector)
  150.           => [1 two (quote (three)) "four" [five]]
  151.      (eq avector (eval avector))
  152.           => t
  153.  
  154.    Here are some functions that relate to vectors:
  155.  
  156.  - Function: vectorp OBJECT
  157.      This function returns `t' if OBJECT is a vector.
  158.  
  159.           (vectorp [a])
  160.                => t
  161.           (vectorp "asdf")
  162.                => nil
  163.  
  164.  - Function: vector &rest OBJECTS
  165.      This function creates and returns a vector whose elements are the
  166.      arguments, OBJECTS.
  167.  
  168.           (vector 'foo 23 [bar baz] "rats")
  169.                => [foo 23 [bar baz] "rats"]
  170.           (vector)
  171.                => []
  172.  
  173.  - Function: make-vector INTEGER OBJECT
  174.      This function returns a new vector consisting of INTEGER elements,
  175.      each initialized to OBJECT.
  176.  
  177.           (setq sleepy (make-vector 9 'Z))
  178.                => [Z Z Z Z Z Z Z Z Z]
  179.  
  180.  - Function: vconcat &rest SEQUENCES
  181.      This function returns a new vector containing all the elements of
  182.      the SEQUENCES.  The arguments SEQUENCES may be lists, vectors, or
  183.      strings.  If no SEQUENCES are given, an empty vector is returned.
  184.  
  185.      The value is a newly constructed vector that is not `eq' to any
  186.      existing vector.
  187.  
  188.           (setq a (vconcat '(A B C) '(D E F)))
  189.                => [A B C D E F]
  190.           (eq a (vconcat a))
  191.                => nil
  192.           (vconcat)
  193.                => []
  194.           (vconcat [A B C] "aa" '(foo (6 7)))
  195.                => [A B C 97 97 foo (6 7)]
  196.  
  197.      When an argument is an integer (not a sequence of integers), it is
  198.      converted to a string of digits making up the decimal printed
  199.      representation of the integer.  This special case exists for
  200.      compatibility with Mocklisp, and we don't recommend you take
  201.      advantage of it.  If you want to convert an integer in this way,
  202.      use `format' (*note Formatting Strings::.) or `int-to-string'
  203.      (*note String Conversion::.).
  204.  
  205.      For other concatenation functions, see `mapconcat' in *Note
  206.      Mapping Functions::, `concat' in *Note Creating Strings::, and
  207.      `append' in *Note Building Lists::.
  208.  
  209.    The `append' function may be used to convert a vector into a list
  210. with the same elements (*note Building Lists::.):
  211.  
  212.      (setq avector [1 two (quote (three)) "four" [five]])
  213.           => [1 two (quote (three)) "four" [five]]
  214.      (append avector nil)
  215.           => (1 two (quote (three)) "four" [five])
  216.  
  217. 
  218. File: elisp,  Node: Symbols,  Next: Evaluation,  Prev: Sequences Arrays Vectors,  Up: Top
  219.  
  220. Symbols
  221. *******
  222.  
  223.    A "symbol" is an object with a unique name.  This chapter describes
  224. symbols, their components, and how they are created and interned.
  225. Property lists are also described.  The uses of symbols as variables
  226. and as function names are described in separate chapters; see *Note
  227. Variables::, and *Note Functions::.  For the precise syntax for
  228. symbols, see *Note Symbol Type::.
  229.  
  230.    You can test whether an arbitrary Lisp object is a symbol with
  231. `symbolp':
  232.  
  233.  - Function: symbolp OBJECT
  234.      This function returns `t' if OBJECT is a symbol, `nil' otherwise.
  235.  
  236. * Menu:
  237.  
  238. * Symbol Components::        Symbols have names, values, function definitions
  239.                                and property lists.
  240. * Definitions::              A definition says how a symbol will be used.
  241. * Creating Symbols::         How symbols are kept unique.
  242. * Property Lists::           Each symbol has a property list
  243.                                for recording miscellaneous information.
  244.  
  245. 
  246. File: elisp,  Node: Symbol Components,  Next: Definitions,  Prev: Symbols,  Up: Symbols
  247.  
  248. Symbol Components
  249. =================
  250.  
  251.    Each symbol has four components (or "cells"), each of which
  252. references another object:
  253.  
  254. Print name
  255.      The "print name cell" holds a string which names the symbol for
  256.      reading and printing.  See `symbol-name' in *Note Creating
  257.      Symbols::.
  258.  
  259. Value
  260.      The "value cell" holds the current value of the symbol as a
  261.      variable.  When a symbol is used as a form, the value of the form
  262.      is the contents of the symbol's value cell.  See `symbol-value' in
  263.      *Note Accessing Variables::.
  264.  
  265. Function
  266.      The "function cell" holds the function definition of the symbol.
  267.      When a symbol is used as a function, its function definition is
  268.      used in its place.  This cell is also used to make a symbol stand
  269.      for a keymap or a keyboard macro, for editor command execution.
  270.      Because each symbol has separate value and function cells,
  271.      variables and function names do not conflict.  See
  272.      `symbol-function' in *Note Function Cells::.
  273.  
  274. Property list
  275.      The "property list cell" holds the property list of the symbol.
  276.      See `symbol-plist' in *Note Property Lists::.
  277.  
  278.    The print name cell always holds a string, and cannot be changed.
  279. The other three cells can be set individually to any specified Lisp
  280. object.
  281.  
  282.    The print name cell holds the string that is the name of the symbol.
  283. Since symbols are represented textually by their names, it is important
  284. not to have two symbols with the same name.  The Lisp reader ensures
  285. this: every time it reads a symbol, it looks for an existing symbol with
  286. the specified name before it creates a new one.  (In GNU Emacs Lisp,
  287. this is done with a hashing algorithm that uses an obarray; see *Note
  288. Creating Symbols::.)
  289.  
  290.    In normal usage, the function cell usually contains a function or
  291. macro, as that is what the Lisp interpreter expects to see there (*note
  292. Evaluation::.).  Keyboard macros (*note Keyboard Macros::.), keymaps
  293. (*note Keymaps::.) and autoload objects (*note Autoloading::.) are also
  294. sometimes stored in the function cell of symbols.  We often refer to
  295. "the function `foo'" when we really mean the function stored in the
  296. function cell of the symbol `foo'.  We make the distinction only when
  297. necessary.
  298.  
  299.    Similarly, the property list cell normally holds a correctly
  300. formatted property list (*note Property Lists::.), as a number of
  301. functions expect to see a property list there.
  302.  
  303.    The function cell or the value cell may be "void", which means that
  304. the cell does not reference any object.  (This is not the same thing as
  305. holding the symbol `void', nor the same as holding the symbol `nil'.)
  306. Examining the value of a cell which is void results in an error, such
  307. as `Symbol's value as variable is void'.
  308.  
  309.    The four functions `symbol-name', `symbol-value', `symbol-plist',
  310. and `symbol-function' return the contents of the four cells.  Here as
  311. an example we show the contents of the four cells of the symbol
  312. `buffer-file-name':
  313.  
  314.      (symbol-name 'buffer-file-name)
  315.           => "buffer-file-name"
  316.      (symbol-value 'buffer-file-name)
  317.           => "/gnu/elisp/symbols.texi"
  318.      (symbol-plist 'buffer-file-name)
  319.           => (variable-documentation 29529)
  320.      (symbol-function 'buffer-file-name)
  321.           => #<subr buffer-file-name>
  322.  
  323. Because this symbol is the variable which holds the name of the file
  324. being visited in the current buffer, the value cell contents we see are
  325. the name of the source file of this chapter of the Emacs Lisp Manual.
  326. The property list cell contains the list `(variable-documentation
  327. 29529)' which tells the documentation functions where to find
  328. documentation about `buffer-file-name' in the `DOC' file.  (29529 is
  329. the offset from the beginning of the `DOC' file where the documentation
  330. for the function begins.)  The function cell contains the function for
  331. returning the name of the file.  `buffer-file-name' names a primitive
  332. function, which has no read syntax and prints in hash notation (*note
  333. Primitive Function Type::.).  A symbol naming a function written in
  334. Lisp would have a lambda expression (or a byte-code object) in this
  335. cell.
  336.  
  337. 
  338. File: elisp,  Node: Definitions,  Next: Creating Symbols,  Prev: Symbol Components,  Up: Symbols
  339.  
  340. Defining Symbols
  341. ================
  342.  
  343.    A "definition" in Lisp is a special form that announces your
  344. intention to use a certain symbol in a particular way.  In Emacs Lisp,
  345. you can define a symbol as a variable, or define it as a function (or
  346. macro), or both independently.
  347.  
  348.    A definition construct typically specifies a value or meaning for the
  349. symbol for one kind of use, plus documentation for its meaning when used
  350. in this way.  Thus, when you define a symbol as a variable, you can
  351. supply an initial value for the variable, plus documentation for the
  352. variable.
  353.  
  354.    `defvar' and `defconst' are special forms that define a symbol as a
  355. global variable.  They are documented in detail in *Note Defining
  356. Variables::.
  357.  
  358.    `defun' defines a symbol as a function, creating a lambda expression
  359. and storing it in the function cell of the symbol.  This lambda
  360. expression thus becomes the function definition of the symbol.  (The
  361. term "function definition", meaning the contents of the function cell,
  362. is derived from the idea that `defun' gives the symbol its definition
  363. as a function.)  *Note Functions::.
  364.  
  365.    `defmacro' defines a symbol as a macro.  It creates a macro object
  366. and stores it in the function cell of the symbol.  Note that a given
  367. symbol can be a macro or a function, but not both at once, because both
  368. macro and function definitions are kept in the function cell, and that
  369. cell can hold only one Lisp object at any given time.  *Note Macros::.
  370.  
  371.    In GNU Emacs Lisp, a definition is not required in order to use a
  372. symbol as a variable or function.  Thus, you can make a symbol a global
  373. variable with `setq', whether you define it first or not.  The real
  374. purpose of definitions is to guide programmers and programming tools.
  375. They inform programmers who read the code that certain symbols are
  376. *intended* to be used as variables, or as functions.  In addition,
  377. utilities such as `etags' and `make-docfile' can recognize definitions,
  378. and add the appropriate information to tag tables and the
  379. `emacs/etc/DOC-VERSION' file. *Note Accessing Documentation::.
  380.  
  381. 
  382. File: elisp,  Node: Creating Symbols,  Next: Property Lists,  Prev: Definitions,  Up: Symbols
  383.  
  384. Creating and Interning Symbols
  385. ==============================
  386.  
  387.    To understand how symbols are created in GNU Emacs Lisp, you must
  388. know how Lisp reads them.  Lisp must ensure that it finds the same
  389. symbol every time it reads the same set of characters.  Failure to do
  390. so would cause complete confusion.
  391.  
  392.    When the Lisp reader encounters a symbol, it reads all the characters
  393. of the name.  Then it "hashes" those characters to find an index in a
  394. table called an "obarray".  Hashing is an efficient method of looking
  395. something up.  For example, instead of searching a telephone book cover
  396. to cover when looking up Jan Jones, you start with the J's and go from
  397. there.  That is a simple version of hashing.  Each element of the
  398. obarray is a "bucket" which holds all the symbols with a given hash
  399. code; to look for a given name, it is sufficient to look through all
  400. the symbols in the bucket for that name's hash code.
  401.  
  402.    If a symbol with the desired name is found, then it is used.  If no
  403. such symbol is found, then a new symbol is created and added to the
  404. obarray bucket.  Adding a symbol to an obarray is called "interning"
  405. it, and the symbol is then called an "interned symbol".  In Emacs Lisp,
  406. a symbol may be interned in only one obarray--if you try to intern the
  407. same symbol in more than one obarray, you will get unpredictable
  408. results.
  409.  
  410.    It is possible for two different symbols to have the same name in
  411. different obarrays; these symbols are not `eq' or `equal'.  However,
  412. this normally happens only as part of abbrev definition (*note
  413. Abbrevs::.).
  414.  
  415.      Common Lisp note: in Common Lisp, a symbol may be interned in
  416.      several obarrays at once.
  417.  
  418.    If a symbol is not in the obarray, then there is no way for Lisp to
  419. find it when its name is read.  Such a symbol is called an "uninterned
  420. symbol" relative to the obarray.  An uninterned symbol has all the
  421. other characteristics of symbols.
  422.  
  423.    In Emacs Lisp, an obarray is represented as a vector.  Each element
  424. of the vector is a bucket; its value is either an interned symbol whose
  425. name hashes to that bucket, or 0 if the bucket is empty.  Each interned
  426. symbol has an internal link (invisible to the user) to the next symbol
  427. in the bucket.  Because these links are invisible, there is no way to
  428. scan the symbols in an obarray except using `mapatoms' (below).  The
  429. order of symbols in a bucket is not significant.
  430.  
  431.    In an empty obarray, every element is 0, and you can create an
  432. obarray with `(make-vector LENGTH 0)'.  *This is the only valid way to
  433. create an obarray.*  Prime numbers as lengths tend to result in good
  434. hashing; lengths one less than a power of two are also good.
  435.  
  436.    *Do not try to create an obarray that is not empty.*  This does not
  437. work--only `intern' can enter a symbol in an obarray properly.  Also,
  438. don't try to put into an obarray of your own a symbol that is already
  439. interned in the main obarray, because in Emacs Lisp a symbol cannot be
  440. in two obarrays at once.
  441.  
  442.    Most of the functions below take a name and sometimes an obarray as
  443. arguments.  A `wrong-type-argument' error is signaled if the name is
  444. not a string, or if the obarray is not a vector.
  445.  
  446.  - Function: symbol-name SYMBOL
  447.      This function returns the string that is SYMBOL's name.  For
  448.      example:
  449.  
  450.           (symbol-name 'foo)
  451.                => "foo"
  452.  
  453.      Changing the string by substituting characters, etc, does change
  454.      the name of the symbol, but fails to update the obarray, so don't
  455.      do it!
  456.  
  457.  - Function: make-symbol NAME
  458.      This function returns a newly-allocated, uninterned symbol whose
  459.      name is NAME (which must be a string).  Its value and function
  460.      definition are void, and its property list is `nil'.  In the
  461.      example below, the value of `sym' is not `eq' to `foo' because it
  462.      is a distinct uninterned symbol whose name is also `foo'.
  463.  
  464.           (setq sym (make-symbol "foo"))
  465.                => foo
  466.           (eq sym 'foo)
  467.                => nil
  468.  
  469.  - Function: intern NAME &optional OBARRAY
  470.      This function returns the interned symbol whose name is NAME.  If
  471.      there is no such symbol in the obarray, a new one is created,
  472.      added to the obarray, and returned.  If OBARRAY is supplied, it
  473.      specifies the obarray to use; otherwise, the value of the global
  474.      variable `obarray' is used.
  475.  
  476.           (setq sym (intern "foo"))
  477.                => foo
  478.           (eq sym 'foo)
  479.                => t
  480.           
  481.           (setq sym1 (intern "foo" other-obarray))
  482.                => foo
  483.           (eq sym 'foo)
  484.                => nil
  485.  
  486.  - Function: intern-soft NAME &optional OBARRAY
  487.      This function returns the symbol whose name is NAME, or `nil' if a
  488.      symbol with that name is not found in the obarray.  Therefore, you
  489.      can use `intern-soft' to test whether a symbol with a given name is
  490.      interned.  If OBARRAY is supplied, it specifies the obarray to
  491.      use; otherwise the value of the global variable `obarray' is used.
  492.  
  493.           (intern-soft "frazzle")        ; No such symbol exists.
  494.                => nil
  495.           (make-symbol "frazzle")        ; Create an uninterned one.
  496.                => frazzle
  497.           (intern-soft "frazzle")        ; That one cannot be found.
  498.                => nil
  499.           (setq sym (intern "frazzle"))  ; Create an interned one.
  500.                => frazzle
  501.           (intern-soft "frazzle")        ; That one can be found!
  502.                => frazzle
  503.           (eq sym 'frazzle)              ; And it is the same one.
  504.                => t
  505.  
  506.  - Variable: obarray
  507.      This variable is the standard obarray for use by `intern' and
  508.      `read'.
  509.  
  510.  - Function: mapatoms FUNCTION &optional OBARRAY
  511.      This function applies FUNCTION to every symbol in OBARRAY.  It
  512.      returns `nil'.  If OBARRAY is not supplied, it defaults to the
  513.      value of `obarray', the standard obarray for ordinary symbols.
  514.  
  515.           (setq count 0)
  516.                => 0
  517.           (defun count-syms (s)
  518.             (setq count (1+ count)))
  519.                => count-syms
  520.           (mapatoms 'count-syms)
  521.                => nil
  522.           count
  523.                => 1871
  524.  
  525.      See `documentation' in *Note Accessing Documentation::, for another
  526.      example using `mapatoms'.
  527.  
  528. 
  529. File: elisp,  Node: Property Lists,  Prev: Creating Symbols,  Up: Symbols
  530.  
  531. Property Lists
  532. ==============
  533.  
  534.    A "property list" ("plist" for short) is a list of paired elements
  535. stored in the property list cell of a symbol.  Each of the pairs
  536. associates a property name (usually a symbol) with a property or value.
  537. Property lists are generally used to record information about a
  538. symbol, such as how to compile it, the name of the file where it was
  539. defined, or perhaps even the grammatical class of the symbol
  540. (representing a word) in a language understanding system.
  541.  
  542.    Character positions in a string or buffer can also have property
  543. lists.  *Note Text Properties::.
  544.  
  545.    The property names and values in a property list can be any Lisp
  546. objects, but the names are usually symbols.  They are compared using
  547. `eq'.  Here is an example of a property list, found on the symbol
  548. `progn' when the compiler is loaded:
  549.  
  550.      (lisp-indent-function 0 byte-compile byte-compile-progn)
  551.  
  552. Here `lisp-indent-function' and `byte-compile' are property names, and
  553. the other two elements are the corresponding values.
  554.  
  555.    Association lists (*note Association Lists::.) are very similar to
  556. property lists.  In contrast to association lists, the order of the
  557. pairs in the property list is not significant since the property names
  558. must be distinct.
  559.  
  560.    Property lists are better than association lists when it is necessary
  561. to attach information to various Lisp function names or variables.  If
  562. all the pairs are recorded in one association list, the program will
  563. need to search that entire list each time a function or variable is to
  564. be operated on.  By contrast, if the information is recorded in the
  565. property lists of the function names or variables themselves, each
  566. search will scan only the length of one property list, which is usually
  567. short.  For this reason, the documentation for a variable is recorded in
  568. a property named `variable-documentation'.  The byte compiler likewise
  569. uses properties to record those functions needing special treatment.
  570.  
  571.    However, association lists have their own advantages.  Depending on
  572. your application, it may be faster to add an association to the front of
  573. an association list than to update a property.  All properties for a
  574. symbol are stored in the same property list, so there is a possibility
  575. of a conflict between different uses of a property name.  (For this
  576. reason, it is a good idea to use property names that are probably
  577. unique, such as by including the name of the library in the property
  578. name.)  An association list may be used like a stack where associations
  579. are pushed on the front of the list and later discarded; this is not
  580. possible with a property list.
  581.  
  582.  - Function: symbol-plist SYMBOL
  583.      This function returns the property list of SYMBOL.
  584.  
  585.  - Function: setplist SYMBOL PLIST
  586.      This function sets SYMBOL's property list to PLIST.  Normally,
  587.      PLIST should be a well-formed property list, but this is not
  588.      enforced.
  589.  
  590.           (setplist 'foo '(a 1 b (2 3) c nil))
  591.                => (a 1 b (2 3) c nil)
  592.           (symbol-plist 'foo)
  593.                => (a 1 b (2 3) c nil)
  594.  
  595.      For symbols in special obarrays, which are not used for ordinary
  596.      purposes, it may make sense to use the property list cell in a
  597.      nonstandard fashion; in fact, the abbrev mechanism does so (*note
  598.      Abbrevs::.).
  599.  
  600.  - Function: get SYMBOL PROPERTY
  601.      This function finds the value of the property named PROPERTY in
  602.      SYMBOL's property list.  If there is no such property, `nil' is
  603.      returned.  Thus, there is no distinction between a value of `nil'
  604.      and the absence of the property.
  605.  
  606.      The name PROPERTY is compared with the existing property names
  607.      using `eq', so any object is a legitimate property.
  608.  
  609.      See `put' for an example.
  610.  
  611.  - Function: put SYMBOL PROPERTY VALUE
  612.      This function puts VALUE onto SYMBOL's property list under the
  613.      property name PROPERTY, replacing any previous value.
  614.  
  615.           (put 'fly 'verb 'transitive)
  616.                =>'transitive
  617.           (put 'fly 'noun '(a buzzing little bug))
  618.                => (a buzzing little bug)
  619.           (get 'fly 'verb)
  620.                => transitive
  621.           (symbol-plist 'fly)
  622.                => (verb transitive noun (a buzzing little bug))
  623.  
  624. 
  625. File: elisp,  Node: Evaluation,  Next: Control Structures,  Prev: Symbols,  Up: Top
  626.  
  627. Evaluation
  628. **********
  629.  
  630.    The "evaluation" of expressions in Emacs Lisp is performed by the
  631. "Lisp interpreter"--a program that receives a Lisp object as input and
  632. computes its "value as an expression".  The value is computed in a
  633. fashion that depends on the data type of the object, following rules
  634. described in this chapter.  The interpreter runs automatically to
  635. evaluate portions of your program, but can also be called explicitly
  636. via the Lisp primitive function `eval'.
  637.  
  638. * Menu:
  639.  
  640. * Intro Eval::  Evaluation in the scheme of things.
  641. * Eval::        How to invoke the Lisp interpreter explicitly.
  642. * Forms::       How various sorts of objects are evaluated.
  643. * Quoting::     Avoiding evaluation (to put constants in the program).
  644.  
  645. 
  646. File: elisp,  Node: Intro Eval,  Next: Eval,  Up: Evaluation
  647.  
  648. Introduction to Evaluation
  649. ==========================
  650.  
  651.    The Lisp interpreter, or evaluator, is the program which computes
  652. the value of an expression which is given to it.  When a function
  653. written in Lisp is called, the evaluator computes the value of the
  654. function by evaluating the expressions in the function body.  Thus,
  655. running any Lisp program really means running the Lisp interpreter.
  656.  
  657.    How the evaluator handles an object depends primarily on the data
  658. type of the object.
  659.  
  660.    A Lisp object which is intended for evaluation is called an
  661. "expression" or a "form".  The fact that expressions are data objects
  662. and not merely text is one of the fundamental differences between
  663. Lisp-like languages and typical programming languages.  Any object can
  664. be evaluated, but in practice only numbers, symbols, lists and strings
  665. are evaluated very often.
  666.  
  667.    It is very common to read a Lisp expression and then evaluate the
  668. expression, but reading and evaluation are separate activities, and
  669. either can be performed alone.  Reading per se does not evaluate
  670. anything; it converts the printed representation of a Lisp object to the
  671. object itself.  It is up to the caller of `read' whether this object is
  672. a form to be evaluated, or serves some entirely different purpose.
  673. *Note Input Functions::.
  674.  
  675.    Do not confuse evaluation with command key interpretation.  The
  676. editor command loop translates keyboard input into a command (an
  677. interactively callable function) using the active keymaps, and then
  678. uses `call-interactively' to invoke the command.  The execution of the
  679. command itself involves evaluation if the command is written in Lisp,
  680. but that is not a part of command key interpretation itself.  *Note
  681. Command Loop::.
  682.  
  683.    Evaluation is a recursive process.  That is, evaluation of a form may
  684. cause `eval' to be called again in order to evaluate parts of the form.
  685. For example, evaluation of a function call first evaluates each
  686. argument of the function call, and then evaluates each form in the
  687. function body.  Consider evaluation of the form `(car x)': the subform
  688. `x' must first be evaluated recursively, so that its value can be
  689. passed as an argument to the function `car'.
  690.  
  691.    The evaluation of forms takes place in a context called the
  692. "environment", which consists of the current values and bindings of all
  693. Lisp variables.(1)  Whenever the form refers to a variable without
  694. creating a new binding for it, the value of the binding in the current
  695. environment is used.  *Note Variables::.
  696.  
  697.    Evaluation of a form may create new environments for recursive
  698. evaluation by binding variables (*note Local Variables::.).  These
  699. environments are temporary and will be gone by the time evaluation of
  700. the form is complete.  The form may also make changes that persist;
  701. these changes are called "side effects".  An example of a form that
  702. produces side effects is `(setq foo 1)'.
  703.  
  704.    Finally, evaluation of one particular function call, `byte-code',
  705. invokes the "byte-code interpreter" on its arguments.  Although the
  706. byte-code interpreter is not the same as the Lisp interpreter, it uses
  707. the same environment as the Lisp interpreter, and may on occasion invoke
  708. the Lisp interpreter.  (*Note Byte Compilation::.)
  709.  
  710.    The details of what evaluation means for each kind of form are
  711. described below (*note Forms::.).
  712.  
  713.    ---------- Footnotes ----------
  714.  
  715.    (1)  This definition of "environment" is specifically not intended
  716. to include all the data which can affect the result of a program.
  717.  
  718. 
  719. File: elisp,  Node: Eval,  Next: Forms,  Prev: Intro Eval,  Up: Evaluation
  720.  
  721. Eval
  722. ====
  723.  
  724.    Most often, forms are evaluated automatically, by virtue of their
  725. occurrence in a program being run.  On rare occasions, you may need to
  726. write code that evaluates a form that is computed at run time, such as
  727. after reading a form from text being edited or getting one from a
  728. property list.  On these occasions, use the `eval' function.
  729.  
  730.    The functions and variables described in this section evaluate
  731. forms, specify limits to the evaluation process, or record recently
  732. returned values.  Loading a file also does evaluation (*note
  733. Loading::.).
  734.  
  735.  - Function: eval FORM
  736.      This is the basic function for performing evaluation.  It evaluates
  737.      FORM in the current environment and returns the result.  How the
  738.      evaluation proceeds depends on the type of the object (*note
  739.      Forms::.).
  740.  
  741.      Since `eval' is a function, the argument expression that appears
  742.      in a call to `eval' is evaluated twice: once as preparation before
  743.      `eval' is called, and again by the `eval' function itself.  Here
  744.      is an example:
  745.  
  746.           (setq foo 'bar)
  747.                => bar
  748.           (setq bar 'baz)
  749.                => baz
  750.           ;; `eval' receives argument `bar', which is the value of `foo'
  751.           (eval foo)
  752.                => baz
  753.  
  754.      The number of currently active calls to `eval' is limited to
  755.      `max-lisp-eval-depth' (see below).
  756.  
  757.  - Command: eval-current-buffer &optional STREAM
  758.      This function evaluates the forms in the current buffer.  It reads
  759.      forms from the buffer and calls `eval' on them until the end of the
  760.      buffer is reached, or until an error is signaled and not handled.
  761.  
  762.      If STREAM is supplied, the variable `standard-output' is bound to
  763.      STREAM during the evaluation (*note Output Functions::.).
  764.  
  765.      `eval-current-buffer' always returns `nil'.
  766.  
  767.  - Command: eval-region START END &optional STREAM
  768.      This function evaluates the forms in the current buffer in the
  769.      region defined by the positions START and END.  It reads forms from
  770.      the region and calls `eval' on them until the end of the region is
  771.      reached, or until an error is signaled and not handled.
  772.  
  773.      If STREAM is supplied, `standard-output' is bound to it for the
  774.      duration of the command.
  775.  
  776.      `eval-region' always returns `nil'.
  777.  
  778.  - Variable: max-lisp-eval-depth
  779.      This variable defines the maximum depth allowed in calls to
  780.      `eval', `apply', and `funcall' before an error is signaled (with
  781.      error message `"Lisp nesting exceeds max-lisp-eval-depth"').
  782.      `eval' is called recursively to evaluate the arguments of Lisp
  783.      function calls and to evaluate bodies of functions.
  784.  
  785.      This limit, with the associated error when it is exceeded, is one
  786.      way that Lisp avoids infinite recursion on an ill-defined function.
  787.  
  788.      The default value of this variable is 200.  If you set it to a
  789.      value less than 100, Lisp will reset it to 100 if the given value
  790.      is reached.
  791.  
  792.      `max-specpdl-size' provides another limit on nesting.  *Note Local
  793.      Variables::.
  794.  
  795.  - Variable: values
  796.      The value of this variable is a list of values returned by all
  797.      expressions which were read from buffers (including the
  798.      minibuffer), evaluated, and printed.  The elements are in order,
  799.      most recent first.
  800.  
  801.           (setq x 1)
  802.                => 1
  803.           (list 'A (1+ 2) auto-save-default)
  804.                => (A 3 t)
  805.           values
  806.                => ((A 3 t) 1 ...)
  807.  
  808.      This variable is useful for referring back to values of forms
  809.      recently evaluated.  It is generally a bad idea to print the value
  810.      of `values' itself, since this may be very long.  Instead, examine
  811.      particular elements, like this:
  812.  
  813.           ;; Refer to the most recent evaluation result.
  814.           (nth 0 values)
  815.                => (A 3 t)
  816.           ;; That put a new element on,
  817.           ;;   so all elements move back one.
  818.           (nth 1 values)
  819.                => (A 3 t)
  820.           ;; This gets the element that was next-to-last
  821.           ;;   before this example.
  822.           (nth 3 values)
  823.                => 1
  824.  
  825. 
  826. File: elisp,  Node: Forms,  Next: Quoting,  Prev: Eval,  Up: Evaluation
  827.  
  828. Kinds of Forms
  829. ==============
  830.  
  831.    A Lisp object that is intended to be evaluated is called a "form".
  832. How Emacs evaluates a form depends on its data type.  Emacs has three
  833. different kinds of form that are evaluated differently: symbols, lists,
  834. and "all other types".  All three kinds are described in this section,
  835. starting with "all other types" which are self-evaluating forms.
  836.  
  837. * Menu:
  838.  
  839. * Self-Evaluating Forms::   Forms that evaluate to themselves.
  840. * Symbol Forms::            Symbols evaluate as variables.
  841. * Classifying Lists::       How to distinguish various sorts of list forms.
  842. * Function Indirection::    When a symbol appears as the car of a list,
  843.                   we find the real function via the symbol.
  844. * Function Forms::          Forms that call functions.
  845. * Macro Forms::             Forms that call macros.
  846. * Special Forms::           "Special forms" are idiosyncratic primitives,
  847.                               most of them extremely important.
  848. * Autoloading::             Functions set up to load files
  849.                               containing their real definitions.
  850.  
  851. 
  852. File: elisp,  Node: Self-Evaluating Forms,  Next: Symbol Forms,  Up: Forms
  853.  
  854. Self-Evaluating Forms
  855. ---------------------
  856.  
  857.    A "self-evaluating form" is any form that is not a list or symbol.
  858. Self-evaluating forms evaluate to themselves: the result of evaluation
  859. is the same object that was evaluated.  Thus, the number 25 evaluates to
  860. 25, and the string `"foo"' evaluates to the string `"foo"'.  Likewise,
  861. evaluation of a vector does not cause evaluation of the elements of the
  862. vector--it returns the same vector with its contents unchanged.
  863.  
  864.      '123               ; An object, shown without evaluation.
  865.           => 123
  866.      123                ; Evaluated as usual---result is the same.
  867.           => 123
  868.      (eval '123)        ; Evaluated ``by hand''---result is the same.
  869.           => 123
  870.      (eval (eval '123)) ; Evaluating twice changes nothing.
  871.           => 123
  872.  
  873.    It is common to write numbers, characters, strings, and even vectors
  874. in Lisp code, taking advantage of the fact that they self-evaluate.
  875. However, it is quite unusual to do this for types that lack a read
  876. syntax, because it is inconvenient and not very useful; however, it is
  877. possible to put them inside Lisp programs when they are constructed
  878. from subexpressions rather than read.  Here is an example:
  879.  
  880.      ;; Build such an expression.
  881.      (setq buffer (list 'print (current-buffer)))
  882.           => (print #<buffer eval.texi>)
  883.      ;; Evaluate it.
  884.      (eval buffer)
  885.           -| #<buffer eval.texi>
  886.           => #<buffer eval.texi>
  887.  
  888. 
  889. File: elisp,  Node: Symbol Forms,  Next: Classifying Lists,  Prev: Self-Evaluating Forms,  Up: Forms
  890.  
  891. Symbol Forms
  892. ------------
  893.  
  894.    When a symbol is evaluated, it is treated as a variable.  The result
  895. is the variable's value, if it has one.  If it has none (if its value
  896. cell is void), an error is signaled.  For more information on the use of
  897. variables, see *Note Variables::.
  898.  
  899.    In the following example, we set the value of a symbol with `setq'.
  900. When the symbol is later evaluated, that value is returned.
  901.  
  902.      (setq a 123)
  903.           => 123
  904.      (eval 'a)
  905.           => 123
  906.      a
  907.           => 123
  908.  
  909.    The symbols `nil' and `t' are treated specially, so that the value
  910. of `nil' is always `nil', and the value of `t' is always `t'.  Thus,
  911. these two symbols act like self-evaluating forms, even though `eval'
  912. treats them like any other symbol.
  913.  
  914. 
  915. File: elisp,  Node: Classifying Lists,  Next: Function Indirection,  Prev: Symbol Forms,  Up: Forms
  916.  
  917. Classification of List Forms
  918. ----------------------------
  919.  
  920.    A form that is a nonempty list is either a function call, a macro
  921. call, or a special form, according to its first element.  These three
  922. kinds of forms are evaluated in different ways, described below.  The
  923. rest of the list consists of "arguments" for the function, macro or
  924. special form.
  925.  
  926.    The first step in evaluating a nonempty list is to examine its first
  927. element.  This element alone determines what kind of form the list is
  928. and how the rest of the list is to be processed.  The first element is
  929. *not* evaluated, as it would be in some Lisp dialects including Scheme.
  930.  
  931. 
  932. File: elisp,  Node: Function Indirection,  Next: Function Forms,  Prev: Classifying Lists,  Up: Forms
  933.  
  934. Symbol Function Indirection
  935. ---------------------------
  936.  
  937.    If the first element of the list is a symbol then evaluation examines
  938. the symbol's function cell, and uses its contents instead of the
  939. original symbol.  If the contents are another symbol, this process,
  940. called "symbol function indirection", is repeated until a non-symbol is
  941. obtained.  *Note Function Names::, for more information about using a
  942. symbol as a name for a function stored in the function cell of the
  943. symbol.
  944.  
  945.    One possible consequence of this process is an infinite loop, in the
  946. event that a symbol's function cell refers to the same symbol.  Or a
  947. symbol may have a void function cell, causing a `void-function' error.
  948. But if neither of these things happens, we eventually obtain a
  949. non-symbol, which ought to be a function or other suitable object.
  950.  
  951.    More precisely, we should now have a Lisp function (a lambda
  952. expression), a byte-code function, a primitive function, a Lisp macro, a
  953. special form, or an autoload object.  Each of these types is a case
  954. described in one of the following sections.  If the object is not one of
  955. these types, the error `invalid-function' is signaled.
  956.  
  957.    The following example illustrates the symbol indirection process.  We
  958. use `fset' to set the function cell of a symbol and `symbol-function'
  959. to get the function cell contents (*note Function Cells::.).
  960. Specifically, we store the symbol `car' into the function cell of
  961. `first', and the symbol `first' into the function cell of `erste'.
  962.  
  963.      ;; Build this function cell linkage:
  964.      ;;   -------------       -----        -------        -------
  965.      ;;  | #<subr car> | <-- | car |  <-- | first |  <-- | erste |
  966.      ;;   -------------       -----        -------        -------
  967.  
  968.      (symbol-function 'car)
  969.           => #<subr car>
  970.  
  971.      (fset 'first 'car)
  972.           => car
  973.  
  974.      (fset 'erste 'first)
  975.           => first
  976.  
  977.      (erste '(1 2 3))   ; Call the function referenced by `erste'.
  978.           => 1
  979.  
  980.    By contrast, the following example calls a function without any
  981. symbol function indirection, because the first element is an anonymous
  982. Lisp function, not a symbol.
  983.  
  984.      ((lambda (arg) (erste arg))
  985.       '(1 2 3))
  986.           => 1
  987.  
  988. After that function is called, its body is evaluated; this does involve
  989. symbol function indirection when calling `erste'.
  990.  
  991.    The built-in function `indirect-function' provides an easy way to
  992. perform symbol function indirection explicitly.
  993.  
  994.  - Function: indirect-function FUNCTION
  995.      This function returns the meaning of FUNCTION as a function.  If
  996.      FUNCTION is a symbol, then it finds FUNCTION's function definition
  997.      and starts over with that value.  If FUNCTION is not a symbol,
  998.      then it returns FUNCTION itself.
  999.  
  1000.      Here is how you could define `indirect-function' in Lisp:
  1001.  
  1002.           (defun indirect-function (function)
  1003.             (if (symbolp function)
  1004.                 (indirect-function (symbol-function function))
  1005.               function))
  1006.  
  1007. 
  1008. File: elisp,  Node: Function Forms,  Next: Macro Forms,  Prev: Function Indirection,  Up: Forms
  1009.  
  1010. Evaluation of Function Forms
  1011. ----------------------------
  1012.  
  1013.    If the first element of a list being evaluated is a Lisp function
  1014. object, byte-code object or primitive function object, then that list is
  1015. a "function call".  For example, here is a call to the function `+':
  1016.  
  1017.      (+ 1 x)
  1018.  
  1019.    When a function call is evaluated, the first step is to evaluate the
  1020. remaining elements of the list in the order they appear.  The results
  1021. are the actual argument values, one argument from each element.  Then
  1022. the function is called with this list of arguments, effectively using
  1023. the function `apply' (*note Calling Functions::.).  If the function is
  1024. written in Lisp, the arguments are used to bind the argument variables
  1025. of the function (*note Lambda Expressions::.); then the forms in the
  1026. function body are evaluated in order, and the result of the last one is
  1027. used as the value of the function call.
  1028.  
  1029. 
  1030. File: elisp,  Node: Macro Forms,  Next: Special Forms,  Prev: Function Forms,  Up: Forms
  1031.  
  1032. Lisp Macro Evaluation
  1033. ---------------------
  1034.  
  1035.    If the first element of a list being evaluated is a macro object,
  1036. then the list is a "macro call".  When a macro call is evaluated, the
  1037. elements of the rest of the list are *not* initially evaluated.
  1038. Instead, these elements themselves are used as the arguments of the
  1039. macro.  The macro definition computes a replacement form, called the
  1040. "expansion" of the macro, which is evaluated in place of the original
  1041. form.  The expansion may be any sort of form: a self-evaluating
  1042. constant, a symbol or a list.  If the expansion is itself a macro call,
  1043. this process of expansion repeats until some other sort of form results.
  1044.  
  1045.    Normally, the argument expressions are not evaluated as part of
  1046. computing the macro expansion, but instead appear as part of the
  1047. expansion, so they are evaluated when the expansion is evaluated.
  1048.  
  1049.    For example, given a macro defined as follows:
  1050.  
  1051.      (defmacro cadr (x)
  1052.        (list 'car (list 'cdr x)))
  1053.  
  1054. an expression such as `(cadr (assq 'handler list))' is a macro call,
  1055. and its expansion is:
  1056.  
  1057.      (car (cdr (assq 'handler list)))
  1058.  
  1059. Note that the argument `(assq 'handler list)' appears in the expansion.
  1060.  
  1061.    *Note Macros::, for a complete description of Emacs Lisp macros.
  1062.  
  1063. 
  1064. File: elisp,  Node: Special Forms,  Next: Autoloading,  Prev: Macro Forms,  Up: Forms
  1065.  
  1066. Special Forms
  1067. -------------
  1068.  
  1069.    A "special form" is a primitive function specially marked so that
  1070. its arguments are not all evaluated.  Special forms define control
  1071. structures or perform variable bindings--things which functions cannot
  1072. do.
  1073.  
  1074.    Each special form has its own rules for which arguments are evaluated
  1075. and which are used without evaluation.  Whether a particular argument is
  1076. evaluated may depend on the results of evaluating other arguments.
  1077.  
  1078.    Here is a list, in alphabetical order, of all of the special forms in
  1079. Emacs Lisp with a reference to where each is described.
  1080.  
  1081. `and'
  1082.      *note Combining Conditions::.
  1083.  
  1084. `catch'
  1085.      *note Catch and Throw::.
  1086.  
  1087. `cond'
  1088.      *note Conditionals::.
  1089.  
  1090. `condition-case'
  1091.      *note Handling Errors::.
  1092.  
  1093. `defconst'
  1094.      *note Defining Variables::.
  1095.  
  1096. `defmacro'
  1097.      *note Defining Macros::.
  1098.  
  1099. `defun'
  1100.      *note Defining Functions::.
  1101.  
  1102. `defvar'
  1103.      *note Defining Variables::.
  1104.  
  1105. `function'
  1106.      *note Anonymous Functions::.
  1107.  
  1108. `if'
  1109.      *note Conditionals::.
  1110.  
  1111. `interactive'
  1112.      *note Interactive Call::.
  1113.  
  1114. `let'
  1115. `let*'
  1116.      *note Local Variables::.
  1117.  
  1118. `or'
  1119.      *note Combining Conditions::.
  1120.  
  1121. `prog1'
  1122. `prog2'
  1123. `progn'
  1124.      *note Sequencing::.
  1125.  
  1126. `quote'
  1127.      *note Quoting::.
  1128.  
  1129. `save-excursion'
  1130.      *note Excursions::.
  1131.  
  1132. `save-restriction'
  1133.      *note Narrowing::.
  1134.  
  1135. `save-window-excursion'
  1136.      *note Window Configurations::.
  1137.  
  1138. `setq'
  1139.      *note Setting Variables::.
  1140.  
  1141. `setq-default'
  1142.      *note Creating Buffer-Local::.
  1143.  
  1144. `track-mouse'
  1145.      *note Mouse Tracking::.
  1146.  
  1147. `unwind-protect'
  1148.      *note Nonlocal Exits::.
  1149.  
  1150. `while'
  1151.      *note Iteration::.
  1152.  
  1153. `with-output-to-temp-buffer'
  1154.      *note Temporary Displays::.
  1155.  
  1156.      Common Lisp note: here are some comparisons of special forms in
  1157.      GNU Emacs Lisp and Common Lisp.  `setq', `if', and `catch' are
  1158.      special forms in both Emacs Lisp and Common Lisp.  `defun' is a
  1159.      special form in Emacs Lisp, but a macro in Common Lisp.
  1160.      `save-excursion' is a special form in Emacs Lisp, but doesn't
  1161.      exist in Common Lisp.  `throw' is a special form in Common Lisp
  1162.      (because it must be able to throw multiple values), but it is a
  1163.      function in Emacs Lisp (which doesn't have multiple values).
  1164.  
  1165. 
  1166. File: elisp,  Node: Autoloading,  Prev: Special Forms,  Up: Forms
  1167.  
  1168. Autoloading
  1169. -----------
  1170.  
  1171.    The "autoload" feature allows you to call a function or macro whose
  1172. function definition has not yet been loaded into Emacs.  When an
  1173. autoload object appears as a symbol's function definition and that
  1174. symbol is used as a function, Emacs will automatically install the real
  1175. definition (plus other associated code) and then call that definition.
  1176. (*Note Autoload::.)
  1177.  
  1178. 
  1179. File: elisp,  Node: Quoting,  Prev: Forms,  Up: Evaluation
  1180.  
  1181. Quoting
  1182. =======
  1183.  
  1184.    The special form `quote' returns its single argument "unchanged".
  1185.  
  1186.  - Special Form: quote OBJECT
  1187.      This special form returns OBJECT, without evaluating it.  This
  1188.      allows symbols and lists, which would normally be evaluated, to be
  1189.      included literally in a program.  (It is not necessary to quote
  1190.      numbers, strings, and vectors since they are self-evaluating.)
  1191.  
  1192.      Because `quote' is used so often in programs, Lisp provides a
  1193.      convenient read syntax for it.  An apostrophe character (`'')
  1194.      followed by a Lisp object (in read syntax) expands to a list whose
  1195.      first element is `quote', and whose second element is the object.
  1196.      Thus, the read syntax `'x' is an abbreviation for `(quote x)'.
  1197.  
  1198.      Here are some examples of expressions that use `quote':
  1199.  
  1200.           (quote (+ 1 2))
  1201.                => (+ 1 2)
  1202.           (quote foo)
  1203.                => foo
  1204.           'foo
  1205.                => foo
  1206.           ''foo
  1207.                => (quote foo)
  1208.           '(quote foo)
  1209.                => (quote foo)
  1210.           ['foo]
  1211.                => [(quote foo)]
  1212.  
  1213.    Other quoting constructs include `function' (*note Anonymous
  1214. Functions::.), which causes an anonymous lambda expression written in
  1215. Lisp to be compiled, and ``' (*note Backquote::.), which is used to
  1216. quote only part of a list, while computing and substituting other parts.
  1217.  
  1218. 
  1219. File: elisp,  Node: Control Structures,  Next: Variables,  Prev: Evaluation,  Up: Top
  1220.  
  1221. Control Structures
  1222. ******************
  1223.  
  1224.    A Lisp program consists of expressions or "forms" (*note Forms::.).
  1225. We control the order of execution of the forms by enclosing them in
  1226. "control structures".  Control structures are special forms which
  1227. control when, whether, or how many times to execute the forms they
  1228. contain.
  1229.  
  1230.    The simplest control structure is sequential execution: first form
  1231. A, then form B, and so on.  This is what happens when you write several
  1232. forms in succession in the body of a function, or at top level in a
  1233. file of Lisp code--the forms are executed in the order they are
  1234. written.  We call this "textual order".  For example, if a function
  1235. body consists of two forms A and B, evaluation of the function
  1236. evaluates first A and then B, and the function's value is the value of
  1237. B.
  1238.  
  1239.    Naturally, Emacs Lisp has many kinds of control structures, including
  1240. other varieties of sequencing, function calls, conditionals, iteration,
  1241. and (controlled) jumps.  The built-in control structures are special
  1242. forms since their subforms are not necessarily evaluated.  You can use
  1243. macros to define your own control structure constructs (*note
  1244. Macros::.).
  1245.  
  1246. * Menu:
  1247.  
  1248. * Sequencing::             Evaluation in textual order.
  1249. * Conditionals::           `if', `cond'.
  1250. * Combining Conditions::   `and', `or', `not'.
  1251. * Iteration::              `while' loops.
  1252. * Nonlocal Exits::         Jumping out of a sequence.
  1253.  
  1254.