]> code.delx.au - gnu-emacs/blobdiff - doc/lispref/control.texi
Merge from origin/emacs-24
[gnu-emacs] / doc / lispref / control.texi
index a9e7236fc3a02566f36a589ab6c4b0948ffb14f7..fa760c45d6ac904ee960e3b33d6de857808437af 100644 (file)
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990-1995, 1998-1999, 2001-2013 Free Software
+@c Copyright (C) 1990-1995, 1998-1999, 2001-2014 Free Software
 @c Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @node Control Structures
@@ -44,6 +44,8 @@ structure constructs (@pxref{Macros}).
 
 @node Sequencing
 @section Sequencing
+@cindex sequencing
+@cindex sequential execution
 
   Evaluating forms in the order they appear is the most common way
 control passes from one form to another.  In some contexts, such as in a
@@ -322,18 +324,19 @@ In the last clause, @code{code} is a variable that gets bound to the value that
 was returned by @code{(get-return-code x)}.
 
 To give a more complex example, a simple interpreter for a little
-expression language could look like:
+expression language could look like (note that this example requires
+lexical binding):
 
 @example
 (defun evaluate (exp env)
   (pcase exp
-    (`(add ,x ,y)         (+ (evaluate x env) (evaluate y env)))
-    (`(call ,fun ,arg)    (funcall (evaluate fun env) (evaluate arg env)))
-    (`(fn ,arg ,body)     (lambda (val)
-                            (evaluate body (cons (cons arg val) env))))
-    ((pred numberp)       exp)
-    ((pred symbolp)       (cdr (assq exp env)))
-    (_                    (error "Unknown expression %S" exp))))
+    (`(add ,x ,y)       (+ (evaluate x env) (evaluate y env)))
+    (`(call ,fun ,arg)  (funcall (evaluate fun env) (evaluate arg env)))
+    (`(fn ,arg ,body)   (lambda (val)
+                          (evaluate body (cons (cons arg val) env))))
+    ((pred numberp)     exp)
+    ((pred symbolp)     (cdr (assq exp env)))
+    (_                  (error "Unknown expression %S" exp))))
 @end example
 
 Where @code{`(add ,x ,y)} is a pattern that checks that @code{exp} is a three
@@ -348,13 +351,9 @@ Here are some sample programs including their evaluation results:
 (evaluate '(add 1 2) nil)                 ;=> 3
 (evaluate '(add x y) '((x . 1) (y . 2)))  ;=> 3
 (evaluate '(call (fn x (add 1 x)) 2) nil) ;=> 3
-(evaluate '(sub 1 2) nil)                 ;=> (error "Unknown expression (sub 1 2)")
+(evaluate '(sub 1 2) nil)                 ;=> error
 @end example
 
-Note that (parts of) @code{pcase} only work as expected with lexical
-binding, so lisp files using @code{pcase} should have enable it
-(@pxref{Using Lexical Binding}, for how to enable lexical binding).
-
 There are two kinds of patterns involved in @code{pcase}, called
 @emph{U-patterns} and @emph{Q-patterns}.  The @var{upattern} mentioned above
 are U-patterns and can take the following forms:
@@ -373,6 +372,10 @@ More specifically, a Q-pattern can take the following forms:
 @item (@var{qpattern1} . @var{qpattern2})
 This pattern matches any cons cell whose @code{car} matches @var{QPATTERN1} and
 whose @code{cdr} matches @var{PATTERN2}.
+@item [@var{qpattern1} @var{qpattern2} @dots{} @var{qpatternm}]
+This pattern matches a vector of length @var{M} whose 0..(@var{M}-1)th
+elements match @var{qpattern1}, @var{qpattern2} @dots{} @var{qpatternm},
+respectively.
 @item @var{atom}
 This pattern matches any atom @code{equal} to @var{atom}.
 @item ,@var{upattern}
@@ -404,6 +407,7 @@ the variable @code{x}.
 
 @node Combining Conditions
 @section Constructs for Combining Conditions
+@cindex combining conditions
 
   This section describes three constructs that are often used together
 with @code{if} and @code{cond} to express complicated conditions.  The
@@ -961,6 +965,7 @@ concept of continuable errors.
 
 @node Processing of Errors
 @subsubsection How Emacs Processes Errors
+@cindex processing of errors
 
 When an error is signaled, @code{signal} searches for an active
 @dfn{handler} for the error.  A handler is a sequence of Lisp
@@ -1255,10 +1260,13 @@ Here's the example at the beginning of this subsection rewritten using
 @end example
 @end defmac
 
-@defmac with-demoted-errors body@dots{}
+@defmac with-demoted-errors format body@dots{}
 This macro is like a milder version of @code{ignore-errors}.  Rather
 than suppressing errors altogether, it converts them into messages.
-Use this form around code that is not expected to signal errors, but
+It uses the string @var{format} to format the message.
+@var{format} should contain a single @samp{%}-sequence; e.g.,
+@code{"Error: %S"}.  Use @code{with-demoted-errors} around code
+that is not expected to signal errors, but
 should be robust if one does occur.  Note that this macro uses
 @code{condition-case-unless-debug} rather than @code{condition-case}.
 @end defmac
@@ -1363,6 +1371,7 @@ and their conditions.
 
 @node Cleanups
 @subsection Cleaning Up from Nonlocal Exits
+@cindex nonlocal exits, cleaning up
 
   The @code{unwind-protect} construct is essential whenever you
 temporarily put a data structure in an inconsistent state; it permits