home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-6 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  47.5 KB  |  1,238 lines

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