aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorPaul Eggert2016-01-30 11:28:37 -0800
committerPaul Eggert2016-01-30 11:28:37 -0800
commit2b41d6a979b0ea361e078891b8763b4ae7be8092 (patch)
treeaef17169e9bf8e59baa82ec7df5c1b64139d9c9f /doc
parentfe9c8b687c5121a413342024b62824a86d2de2be (diff)
parent71468e00735a44e19814a73e8f9013c0f272c342 (diff)
downloademacs-2b41d6a979b0ea361e078891b8763b4ae7be8092.tar.gz
emacs-2b41d6a979b0ea361e078891b8763b4ae7be8092.zip
-
Diffstat (limited to 'doc')
-rw-r--r--doc/emacs/dired.texi26
-rw-r--r--doc/lispref/control.texi224
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/functions.texi225
4 files changed, 390 insertions, 86 deletions
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 92c1fd5a041..123f1aea936 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -778,27 +778,31 @@ Byte compile the specified Emacs Lisp files
778Compilation, elisp, The Emacs Lisp Reference Manual}. 778Compilation, elisp, The Emacs Lisp Reference Manual}.
779 779
780@kindex A @r{(Dired)} 780@kindex A @r{(Dired)}
781@findex dired-do-search 781@findex dired-do-find-regexp
782@cindex search multiple files (in Dired) 782@cindex search multiple files (in Dired)
783@item A @var{regexp} @key{RET} 783@item A @var{regexp} @key{RET}
784Search all the specified files for the regular expression @var{regexp} 784Search all the specified files for the regular expression @var{regexp}
785(@code{dired-do-search}). 785(@code{dired-do-find-regexp}).
786 786
787This command is a variant of @code{tags-search}. The search stops at 787This command is a variant of @code{xref-find-references}
788the first match it finds; use @kbd{M-x tags-loop-continue} to resume 788(@pxref{Identifier Search}), it displays the @file{*xref*} buffer,
789the search and find the next match. @xref{Identifier Search}. 789where you can navigate between matches and display them as needed
790using the commands described in @ref{Xref Commands}.
790 791
791@kindex Q @r{(Dired)} 792@kindex Q @r{(Dired)}
792@findex dired-do-query-replace-regexp 793@findex dired-do-find-regexp-and-replace
793@cindex search and replace in multiple files (in Dired) 794@cindex search and replace in multiple files (in Dired)
794@item Q @var{regexp} @key{RET} @var{to} @key{RET} 795@item Q @var{regexp} @key{RET} @var{to} @key{RET}
795Perform @code{query-replace-regexp} on each of the specified files, 796Perform @code{query-replace-regexp} on each of the specified files,
796replacing matches for @var{regexp} with the string 797replacing matches for @var{regexp} with the string
797@var{to} (@code{dired-do-query-replace-regexp}). 798@var{to} (@code{dired-do-find-regexp-and-replace}).
798 799
799This command is a variant of @code{tags-query-replace}. If you exit the 800This command is a variant of @code{xref-query-replace}. It presents
800query replace loop, you can use @kbd{M-x tags-loop-continue} to resume 801an @file{*xref*} buffer that lists all the matches of @var{regexp},
801the scan and replace more matches. @xref{Identifier Search}. 802and you can use the special commands in that buffer (@pxref{Xref
803Commands}). In particular, if you exit the query replace loop, you
804can use @kbd{r} in that buffer to replace more matches.
805@xref{Identifier Search}.
802@end table 806@end table
803 807
804@node Shell Commands in Dired 808@node Shell Commands in Dired
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 008a991102b..df60347f839 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -297,36 +297,147 @@ For example:
297@cindex pcase 297@cindex pcase
298@cindex pattern matching 298@cindex pattern matching
299 299
300To compare a particular value against various possible cases, the macro 300The @code{cond} form lets you choose between alternatives using
301@code{pcase} can come handy. It takes the following form: 301predicate conditions that compare values of expressions against
302specific values known and written in advance. However, sometimes it
303is useful to select alternatives based on more general conditions that
304distinguish between broad classes of values. The @code{pcase} macro
305allows to choose between alternatives based on matching the value of
306an expression against a series of patterns. A pattern can be a
307literal value (comparison to literal values is what @code{cond} does),
308or it can be a more general description of the expected structure of
309the expression's value.
310
311@defmac pcase expression &rest clauses
312Evaluate @var{expression} and choose among an arbitrary number of
313alternatives based on the value of @var{expression}. The possible
314alternatives are specified by @var{clauses}, each of which must be a
315list of the form @code{(@var{pattern} @var{body-forms})}.
316@code{pcase} tries to match the value of @var{expression} to the
317@var{pattern} of each clause, in textual order. If the value matches,
318the clause succeeds; @code{pcase} then evaluates its @var{body-forms},
319and returns the value of the last of @var{body-forms}. Any remaining
320@var{clauses} are ignored.
321
322The @var{pattern} part of a clause can be of one of two types:
323@dfn{QPattern}, a pattern quoted with a backquote; or a
324@dfn{UPattern}, which is not quoted. UPatterns are simpler, so we
325describe them first.
326
327Note: In the description of the patterns below, we use ``the value
328being matched'' to refer to the value of the @var{expression} that is
329the first argument of @code{pcase}.
330
331A UPattern can have one of the following forms:
302 332
303@example 333@table @code
304(pcase @var{exp} @var{branch}1 @var{branch}2 @var{branch}3 @dots{})
305@end example
306 334
307where each @var{branch} takes the form @code{(@var{upattern} 335@item '@var{val}
308@var{body-forms}@dots{})}. 336Matches if the value being matched is @code{equal} to @var{val}.
337@item @var{atom}
338Matches any @var{atom}, which can be a keyword, a number, or a string.
339(These are self-quoting, so this kind of UPattern is actually a
340shorthand for @code{'@var{atom}}.)
341@item _
342Matches any value. This is known as @dfn{don't care} or @dfn{wildcard}.
343@item @var{symbol}
344Matches any value, and additionally let-binds @var{symbol} to the
345value it matched, so that you can later refer to it, either in the
346@var{body-forms} or also later in the pattern.
347@item (pred @var{predfun})
348Matches if the predicate function @var{predfun} returns non-@code{nil}
349when called with the value being matched as its argument.
350@var{predfun} can be one of the possible forms described below.
351@item (guard @var{boolean-expression})
352Matches if @var{boolean-expression} evaluates to non-@code{nil}. This
353allows to include in a UPattern boolean conditions that refer to
354symbols bound to values (including the value being matched) by
355previous UPatterns. Typically used inside an @code{and} UPattern, see
356below. For example, @w{@code{(and x (guard (< x 10)))}} is a pattern
357which matches any number smaller than 10 and let-binds the variable
358@code{x} to that number.
359@item (let @var{upattern} @var{expression})
360Matches if the specified @var{expression} matches the specified
361@var{upattern}. This allows to match a pattern against the value of
362an @emph{arbitrary} expression, not just the expression that is the
363first argument to @code{pcase}. (It is called @code{let} because
364@var{upattern} can bind symbols to values using the @var{symbol}
365UPattern.)
366@item (app @var{function} @var{upattern})
367Matches if @var{function} applied to the value being matched returns a
368value that matches @var{upattern}. This is like the @code{pred}
369UPattern, except that it tests the result against @var{UPattern},
370rather than against a boolean truth value. The @var{function} call can
371use one of the forms described below.
372@item (or @var{upattern1} @var{upattern2}@dots{})
373Matches if one the argument UPatterns matches. As soon as the first
374matching UPattern is found, the rest are not tested. For this reason,
375if any of the UPatterns let-bind symbols to the matched value, they
376should all bind the same symbols.
377@item (and @var{upattern1} @var{upattern2}@dots{})
378Matches if all the argument UPatterns match.
379@end table
380
381The function calls used in the @code{pred} and @code{app} UPatterns
382can have one of the following forms:
383
384@table @asis
385@item function symbol, like @code{integerp}
386In this case, the named function is applied to the value being
387matched.
388@item lambda-function @code{(lambda (@var{arg}) @var{body})}
389In this case, the lambda-function is called with one argument, the
390value being matched.
391@item @code{(@var{func} @var{args}@dots{})}
392This is a function call with @var{n} specified arguments; the function
393is called with these @var{n} arguments and an additional @var{n}+1-th
394argument that is the value being matched.
395@end table
309 396
310It will first evaluate @var{exp} and then compare the value against each 397Here's an illustrative example of using UPatterns:
311@var{upattern} to see which @var{branch} to use, after which it will run the
312corresponding @var{body-forms}. A common use case is to distinguish
313between a few different constant values:
314 398
399@c FIXME: This example should use every one of the UPatterns described
400@c above at least once.
315@example 401@example
316(pcase (get-return-code x) 402(pcase (get-return-code x)
317 (`success (message "Done!")) 403 ('success (message "Done!"))
318 (`would-block (message "Sorry, can't do it now")) 404 ('would-block (message "Sorry, can't do it now"))
319 (`read-only (message "The shmliblick is read-only")) 405 ('read-only (message "The shmliblick is read-only"))
320 (`access-denied (message "You do not have the needed rights")) 406 ('access-denied (message "You do not have the needed rights"))
321 (code (message "Unknown return code %S" code))) 407 (code (message "Unknown return code %S" code)))
322@end example 408@end example
323 409
324In the last clause, @code{code} is a variable that gets bound to the value that 410The QPatterns are more powerful. They allow to match the value of the
325was returned by @code{(get-return-code x)}. 411@var{expression} that is the first argument of @code{pcase} against
412specifications of its @emph{structure}. For example, you can specify
413that the value must be a list of 2 elements whose first element is a
414string and the second element is a number. QPatterns can have one of
415the following forms:
416
417@table @code
418@item `(@var{qpattern1} . @var{qpattern2})
419Matches if the value being matched is a cons cell whose @code{car}
420matches @var{qpattern1} and whose @code{cdr} matches @var{qpattern2}.
421@item `[@var{qpattern1} @var{qpattern2} @dots{} @var{qpatternm}]
422Matches if the value being matched is a vector of length @var{m} whose
423@code{0}..@code{(@var{m}-1)}th elements match @var{qpattern1},
424@var{qpattern2} @dots{} @var{qpatternm}, respectively.
425@item `(,@var{upattern1} ,@var{upattern2} @dots{})
426Matches if the value being matched is a list whose elements match the
427corresponding @var{upattern1}, @var{upattern2}, etc.
428@item @var{atom}
429Matches if corresponding element of the value being matched is
430@code{equal} to the specified @var{atom}.
431@item ,@var{upattern}
432Matches if the corresponding element of the value being matched
433matches the specified @var{upattern}.
434@end table
435
436@end defmac
326 437
327To give a more complex example, a simple interpreter for a little 438Here is an example of using @code{pcase} to implement a simple
328expression language could look like (note that this example requires 439interpreter for a little expression language (note that this example
329lexical binding): 440requires lexical binding, @pxref{Lexical Binding}):
330 441
331@example 442@example
332(defun evaluate (exp env) 443(defun evaluate (exp env)
@@ -340,13 +451,19 @@ lexical binding):
340 (_ (error "Unknown expression %S" exp)))) 451 (_ (error "Unknown expression %S" exp))))
341@end example 452@end example
342 453
343Where @code{`(add ,x ,y)} is a pattern that checks that @code{exp} is a three 454Here @code{`(add ,x ,y)} is a pattern that checks that @code{exp} is a
344element list starting with the symbol @code{add}, then extracts the second and 455three-element list starting with the literal symbol @code{add}, then
345third elements and binds them to the variables @code{x} and @code{y}. 456extracts the second and third elements and binds them to the variables
346@code{(pred numberp)} is a pattern that simply checks that @code{exp} 457@code{x} and @code{y}. Then it evaluates @code{x} and @code{y} and
347is a number, and @code{_} is the catch-all pattern that matches anything. 458adds the results. The @code{call} and @code{fn} patterns similarly
459implement two flavors of function calls. @code{(pred numberp)} is a
460pattern that simply checks that @code{exp} is a number and if so,
461evaluates it. @code{(pred symbolp)} matches symbols, and returns
462their association. Finally, @code{_} is the catch-all pattern that
463matches anything, so it's suitable for reporting syntax errors.
348 464
349Here are some sample programs including their evaluation results: 465Here are some sample programs in this small language, including their
466evaluation results:
350 467
351@example 468@example
352(evaluate '(add 1 2) nil) ;=> 3 469(evaluate '(add 1 2) nil) ;=> 3
@@ -355,56 +472,13 @@ Here are some sample programs including their evaluation results:
355(evaluate '(sub 1 2) nil) ;=> error 472(evaluate '(sub 1 2) nil) ;=> error
356@end example 473@end example
357 474
358There are two kinds of patterns involved in @code{pcase}, called 475Additional UPatterns can be defined using the @code{pcase-defmacro}
359@emph{U-patterns} and @emph{Q-patterns}. The @var{upattern} mentioned above 476macro.
360are U-patterns and can take the following forms:
361 477
362@table @code 478@defmac pcase-defmacro name args &rest body
363@item `@var{qpattern} 479Define a new UPattern for @code{pcase}. The UPattern will have the
364This is one of the most common form of patterns. The intention is to mimic the 480form @code{(@var{name} @var{args})}.
365backquote macro: this pattern matches those values that could have been built 481@end defmac
366by such a backquote expression. Since we're pattern matching rather than
367building a value, the unquote does not indicate where to plug an expression,
368but instead it lets one specify a U-pattern that should match the value at
369that location.
370
371More specifically, a Q-pattern can take the following forms:
372@table @code
373@item (@var{qpattern1} . @var{qpattern2})
374This pattern matches any cons cell whose @code{car} matches @var{qpattern1} and
375whose @code{cdr} matches @var{qpattern2}.
376@item [@var{qpattern1} @var{qpattern2} @dots{} @var{qpatternm}]
377This pattern matches a vector of length @var{M} whose 0..(@var{M}-1)th
378elements match @var{qpattern1}, @var{qpattern2} @dots{} @var{qpatternm},
379respectively.
380@item @var{atom}
381This pattern matches any atom @code{equal} to @var{atom}.
382@item ,@var{upattern}
383This pattern matches any object that matches the @var{upattern}.
384@end table
385
386@item @var{symbol}
387A mere symbol in a U-pattern matches anything, and additionally let-binds this
388symbol to the value that it matched, so that you can later refer to it, either
389in the @var{body-forms} or also later in the pattern.
390@item _
391This so-called @emph{don't care} pattern matches anything, like the previous
392one, but unlike symbol patterns it does not bind any variable.
393@item (pred @var{pred})
394This pattern matches if the function @var{pred} returns non-@code{nil} when
395called with the object being matched.
396@item (or @var{upattern1} @var{upattern2}@dots{})
397This pattern matches as soon as one of the argument patterns succeeds.
398All argument patterns should let-bind the same variables.
399@item (and @var{upattern1} @var{upattern2}@dots{})
400This pattern matches only if all the argument patterns succeed.
401@item (guard @var{exp})
402This pattern ignores the object being examined and simply succeeds if @var{exp}
403evaluates to non-@code{nil} and fails otherwise. It is typically used inside
404an @code{and} pattern. For example, @code{(and x (guard (< x 10)))}
405is a pattern which matches any number smaller than 10 and let-binds it to
406the variable @code{x}.
407@end table
408 482
409@node Combining Conditions 483@node Combining Conditions
410@section Constructs for Combining Conditions 484@section Constructs for Combining Conditions
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index da519f579c9..4c1541e98c6 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -536,6 +536,7 @@ Functions
536* Calling Functions:: How to use an existing function. 536* Calling Functions:: How to use an existing function.
537* Mapping Functions:: Applying a function to each element of a list, etc. 537* Mapping Functions:: Applying a function to each element of a list, etc.
538* Anonymous Functions:: Lambda expressions are functions with no names. 538* Anonymous Functions:: Lambda expressions are functions with no names.
539* Generic Functions:: Polymorphism, Emacs-style.
539* Function Cells:: Accessing or setting the function definition 540* Function Cells:: Accessing or setting the function definition
540 of a symbol. 541 of a symbol.
541* Closures:: Functions that enclose a lexical environment. 542* Closures:: Functions that enclose a lexical environment.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 1e8e7540395..c5f5b4c22c4 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -18,6 +18,7 @@ define them.
18* Calling Functions:: How to use an existing function. 18* Calling Functions:: How to use an existing function.
19* Mapping Functions:: Applying a function to each element of a list, etc. 19* Mapping Functions:: Applying a function to each element of a list, etc.
20* Anonymous Functions:: Lambda expressions are functions with no names. 20* Anonymous Functions:: Lambda expressions are functions with no names.
21* Generic Functions:: Polymorphism, Emacs-style.
21* Function Cells:: Accessing or setting the function definition 22* Function Cells:: Accessing or setting the function definition
22 of a symbol. 23 of a symbol.
23* Closures:: Functions that enclose a lexical environment. 24* Closures:: Functions that enclose a lexical environment.
@@ -1092,6 +1093,230 @@ the compiled code. The byte-compiler cannot assume this list is a
1092function, even though it looks like one, since it does not know that 1093function, even though it looks like one, since it does not know that
1093@code{change-property} intends to use it as a function. 1094@code{change-property} intends to use it as a function.
1094 1095
1096@node Generic Functions
1097@section Generic Functions
1098@cindex generic functions
1099@cindex polymorphism
1100
1101 Functions defined using @code{defun} have a hard-coded set of
1102assumptions about the types and expected values of their arguments.
1103For example, a function that was designed to handle values of its
1104argument that are either numbers or lists of numbers will fail or
1105signal an error if called with a value of any other type, such as a
1106vector or a string. This happens because the implementation of the
1107function is not prepared to deal with types other than those assumed
1108during the design.
1109
1110 By contrast, object-oriented programs use @dfn{polymorphic
1111functions}: a set of specialized functions having the same name, each
1112one of which was written for a certain specific set of argument types.
1113Which of the functions is actually called is decided at run time based
1114on the types of the actual arguments.
1115
1116@cindex CLOS
1117 Emacs provides support for polymorphism. Like other Lisp
1118environments, notably Common Lisp and its Common Lisp Object System
1119(@acronym{CLOS}), this support is based on @dfn{generic functions}.
1120The Emacs generic functions closely follow @acronym{CLOS}, including
1121use of similar names, so if you have experience with @acronym{CLOS},
1122the rest of this section will sound very familiar.
1123
1124 A generic function specifies an abstract operation, by defining its
1125name and list of arguments, but (usually) no implementation. The
1126actual implementation for several specific classes of arguments is
1127provided by @dfn{methods}, which should be defined separately. Each
1128method that implements a generic function has the same name as the
1129generic function, but the method's definition indicates what kinds of
1130arguments it can handle by @dfn{specializing} the arguments defined by
1131the generic function. These @dfn{argument specializers} can be more
1132or less specific; for example, a @code{string} type is more specific
1133than a more general type, such as @code{sequence}.
1134
1135 Note that, unlike in message-based OO languages, such as C@t{++} and
1136Simula, methods that implement generic functions don't belong to a
1137class, they belong to the generic function they implement.
1138
1139 When a generic function is invoked, it selects the applicable
1140methods by comparing the actual arguments passed by the caller with
1141the argument specializers of each method. A method is applicable if
1142the actual arguments of the call are compatible with the method's
1143specializers. If more than one method is applicable, they are
1144combined using certain rules, described below, and the combination
1145then handles the call.
1146
1147@defmac cl-defgeneric name arguments [documentation] [options-and-methods@dots{}] &rest body
1148This macro defines a generic function with the specified @var{name}
1149and @var{arguments}. If @var{body} is present, it provides the
1150default implementation. If @var{documentation} is present (it should
1151always be), it specifies the documentation string for the generic
1152function, in the form @code{(:documentation @var{docstring})}. The
1153optional @var{options-and-methods} can be one of the following forms:
1154
1155@table @code
1156@item (declare @var{declarations})
1157A declare form, as described in @ref{Declare Form}.
1158@item (:argument-precedence-order &rest @var{args})
1159This form affects the sorting order for combining applicable methods.
1160Normally, when two methods are compared during combination, method
1161arguments are examined left to right, and the first method whose
1162argument specializer is more specific will come before the other one.
1163The order defined by this form overrides that, and the arguments are
1164examined according to their order in this form, and not left to right.
1165@item (:method [@var{qualifiers}@dots{}] args &rest body)
1166This form defines a method like @code{cl-defmethod} does.
1167@end table
1168@end defmac
1169
1170@defmac cl-defmethod name [qualifier] arguments &rest [docstring] body
1171This macro defines a particular implementation for the generic
1172function called @var{name}. The implementation code is given by
1173@var{body}. If present, @var{docstring} is the documentation string
1174for the method. The @var{arguments} list, which must be identical in
1175all the methods that implement a generic function, and must match the
1176argument list of that function, provides argument specializers of the
1177form @code{(@var{arg} @var{spec})}, where @var{arg} is the argument
1178name as specified in the @code{cl-defgeneric} call, and @var{spec} is
1179one of the following specializer forms:
1180
1181@table @code
1182@item @var{type}
1183This specializer requires the argument to be of the given @var{type},
1184one of the types from the type hierarchy described below.
1185@item (eql @var{object})
1186This specializer requires the argument be @code{eql} to the given
1187@var{object}.
1188@item (head @var{object})
1189The argument must be a cons cell whose @code{car} is @code{eql} to
1190@var{object}.
1191@item @var{struct-tag}
1192The argument must be an instance of a class named @var{struct-tag}
1193defined with @code{cl-defstruct} (@pxref{Structures,,, cl, Common Lisp
1194Extensions for GNU Emacs Lisp}), or of one of its parent classes.
1195@end table
1196
1197Alternatively, the argument specializer can be of the form
1198@code{&context (@var{expr} @var{spec})}, in which case the value of
1199@var{expr} must be compatible with the specializer provided by
1200@var{spec}; @var{spec} can be any of the forms described above. In
1201other words, this form of specializer uses the value of @var{expr}
1202instead of arguments for the decision whether the method is
1203applicable. For example, @code{&context (overwrite-mode (eql t))}
1204will make the method compatible only when @code{overwrite-mode} is
1205turned on.
1206
1207The type specializer, @code{(@var{arg} @var{type})}, can specify one
1208of the @dfn{system types} in the following list. When a parent type
1209is specified, an argument whose type is any of its more specific child
1210types, as well as grand-children, grand-grand-children, etc. will also
1211be compatible.
1212
1213@table @code
1214@item integer
1215Parent type: @code{number}.
1216@item number
1217@item null
1218Parent type: @code{symbol}
1219@item symbol
1220@item string
1221Parent type: @code{array}.
1222@item array
1223Parent type: @code{sequence}.
1224@item cons
1225Parent type: @code{list}.
1226@item list
1227Parent type: @code{sequence}.
1228@item marker
1229@item overlay
1230@item float
1231Parent type: @code{number}.
1232@item window-configuration
1233@item process
1234@item window
1235@item subr
1236@item compiled-function
1237@item buffer
1238@item char-table
1239Parent type: @code{array}.
1240@item bool-vector
1241Parent type: @code{array}.
1242@item vector
1243Parent type: @code{array}.
1244@item frame
1245@item hash-table
1246@item font-spec
1247@item font-entity
1248@item font-object
1249@end table
1250
1251The optional @var{qualifier} allows to combine several applicable
1252methods. If it is not present, the defined method is a @dfn{primary}
1253method, responsible for providing the primary implementation of the
1254generic function for the specialized arguments. You can also define
1255@dfn{auxiliary methods}, by using one of the following values as
1256@var{qualifier}:
1257
1258@table @code
1259@item :before
1260This auxiliary method will run before the primary method. More
1261accurately, all the @code{:before} methods will run before the
1262primary, in the most-specific-first order.
1263@item :after
1264This auxiliary method will run after the primary method. More
1265accurately, all such methods will run after the primary, in the
1266most-specific-last order.
1267@item :around
1268This auxiliary method will run @emph{instead} of the primary method.
1269The most specific of such methods will be run before any other method.
1270Such methods normally use @code{cl-call-next-method}, described below,
1271to invoke the other auxiliary or primary methods.
1272@item :extra @var{string}
1273This allows to add more methods, distinguished by @var{string}, for
1274the same specializers and qualifiers.
1275@end table
1276@end defmac
1277
1278@cindex dispatch of methods for generic function
1279@cindex multiple-dispatch methods
1280Each time a generic function is called, it builds the @dfn{effective
1281method} which will handle this invocation by combining the applicable
1282methods defined for the function. The process of finding the
1283applicable methods and producing the effective method is called
1284@dfn{dispatch}. The applicable methods are those all of whose
1285specializers are compatible with the actual arguments of the call.
1286Since all of the arguments must be compatible with the specializers,
1287they all determine whether a method is applicable. Methods that
1288explicitly specialize more than one argument are called
1289@dfn{multiple-dispatch methods}.
1290
1291The applicable methods are sorted into the order in which they will be
1292combined. The method whose left-most argument specializer is the most
1293specific one will come first in the order. (Specifying
1294@code{:argument-precedence-order} as part of @code{cl-defmethod}
1295overrides that, as described above.) If the method body calls
1296@code{cl-call-next-method}, the next most-specific method will run.
1297If there are applicable @code{:around} methods, the most-specific of
1298them will run first; it should call @code{cl-call-next-method} to run
1299any of the less specific @code{:around} methods. Next, the
1300@code{:before} methods run in the order of their specificity, followed
1301by the primary method, and lastly the @code{:after} methods in the
1302reverse order of their specificity.
1303
1304@defun cl-call-next-method &rest args
1305When invoked from within the lexical body of a primary or an
1306@code{:around} auxiliary method, call the next applicable method for
1307the same generic function. Normally, it is called with no arguments,
1308which means to call the next applicable method with the same arguments
1309that the calling method was invoked. Otherwise, the specified
1310arguments are used instead.
1311@end defun
1312
1313@defun cl-next-method-p
1314This function, when called from within the lexical body of a primary
1315or an @code{:around} auxiliary method, returns non-@code{nil} if there
1316is a next method to call.
1317@end defun
1318
1319
1095@node Function Cells 1320@node Function Cells
1096@section Accessing Function Cell Contents 1321@section Accessing Function Cell Contents
1097 1322