]> code.delx.au - gnu-emacs/blobdiff - lispref/functions.texi
(Accepting Output): accept-process-output
[gnu-emacs] / lispref / functions.texi
index 26c2449fee62ca2f346cec765c4c8f0aec337085..eedfa8c124f9f97b5112955067f4d3ee754192c3 100644 (file)
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2004
-@c   Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
+@c   2002, 2003, 2004, 2005, 2006, 2007  Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/functions
 @node Functions, Macros, Variables, Top
@@ -21,6 +21,7 @@ define them.
 * Anonymous Functions::   Lambda expressions are functions with no names.
 * Function Cells::        Accessing or setting the function definition
                             of a symbol.
+* Obsolete Functions::    Declaring functions obsolete.
 * Inline Functions::     Defining functions that the compiler will open code.
 * Function Safety::       Determining whether a function is safe to call.
 * Related Topics::        Cross-references to specific Lisp primitives
@@ -98,7 +99,7 @@ Keyboard macros (strings and vectors) are commands also, even though
 they are not functions.  A symbol is a command if its function
 definition is a command; such symbols can be invoked with @kbd{M-x}.
 The symbol is a function as well if the definition is a function.
-@xref{Command Overview}.
+@xref{Interactive Call}.
 
 @item keystroke command
 @cindex keystroke command
@@ -151,7 +152,6 @@ function.  For example:
 @end defun
 
 @defun subr-arity subr
-@tindex subr-arity
 This function provides information about the argument list of a
 primitive, @var{subr}.  The returned value is a pair
 @code{(@var{min} . @var{max})}.  @var{min} is the minimum number of
@@ -293,6 +293,7 @@ variables.
 @kindex wrong-number-of-arguments
 @cindex argument binding
 @cindex binding arguments
+@cindex argument lists, features
 
   Our simple sample function, @code{(lambda (a b c) (+ a b c))},
 specifies three argument variables, so it must be called with three
@@ -485,7 +486,7 @@ more convenient than making the function definition point to itself
 practice).
 
   We often identify functions with the symbols used to name them.  For
-example, we often speak of ``the function @code{car}'', not
+example, we often speak of ``the function @code{car},'' not
 distinguishing between the symbol @code{car} and the primitive
 subr-object that is its function definition.  For most purposes, the
 distinction is not important.
@@ -524,9 +525,9 @@ defines the symbol @var{name} as a function that looks like this:
 @var{name}.  It returns the value @var{name}, but usually we ignore this
 value.
 
-As described previously (@pxref{Lambda Expressions}),
-@var{argument-list} is a list of argument names and may include the
-keywords @code{&optional} and @code{&rest}.  Also, the first two of the
+As described previously, @var{argument-list} is a list of argument
+names and may include the keywords @code{&optional} and @code{&rest}
+(@pxref{Lambda Expressions}).  Also, the first two of the
 @var{body-forms} may be a documentation string and an interactive
 declaration.
 
@@ -583,6 +584,7 @@ defined is often done deliberately, and there is no way to distinguish
 deliberate redefinition from unintentional redefinition.
 @end defspec
 
+@cindex function aliases
 @defun defalias name definition &optional docstring
 @anchor{Definition of defalias}
 This special form defines the symbol @var{name} as a function, with
@@ -601,7 +603,7 @@ which file defined the function, just like @code{defun}
 
 By contrast, in programs that manipulate function definitions for other
 purposes, it is better to use @code{fset}, which does not keep such
-records.
+records.  @xref{Function Cells}.
 @end defun
 
   You cannot create a new primitive function with @code{defun} or
@@ -766,12 +768,10 @@ in turn, and returns a list of the results.
 The argument @var{sequence} can be any kind of sequence except a
 char-table; that is, a list, a vector, a bool-vector, or a string.  The
 result is always a list.  The length of the result is the same as the
-length of @var{sequence}.
+length of @var{sequence}.  For example:
 
 @smallexample
 @group
-@exdent @r{For example:}
-
 (mapcar 'car '((a b) (c d) (e f)))
      @result{} (a c e)
 (mapcar '1+ [1 2 3])
@@ -806,7 +806,6 @@ Return the list of results."
 @end defun
 
 @defun mapc function sequence
-@tindex mapc
 @code{mapc} is like @code{mapcar} except that @var{function} is used for
 side-effects only---the values it returns are ignored, not collected
 into a list.  @code{mapc} always returns @var{sequence}.
@@ -847,7 +846,7 @@ bool-vector, or a string.
 
   In Lisp, a function is a list that starts with @code{lambda}, a
 byte-code function compiled from such a list, or alternatively a
-primitive subr-object; names are ``extra''.  Although usually functions
+primitive subr-object; names are ``extra.''  Although usually functions
 are defined with @code{defun} and given names at the same time, it is
 occasionally more concise to use an explicit lambda expression---an
 anonymous function.  Such a list is valid wherever a function name is.
@@ -1150,6 +1149,39 @@ file to redefine a function defined elsewhere.  If you want to modify
 a function defined by another package, it is cleaner to use
 @code{defadvice} (@pxref{Advising Functions}).
 
+@node Obsolete Functions
+@section Declaring Functions Obsolete
+
+You can use @code{make-obsolete} to declare a function obsolete.  This
+indicates that the function may be removed at some stage in the future.
+
+@defun make-obsolete obsolete-name current-name &optional when
+This function makes the byte compiler warn that the function
+@var{obsolete-name} is obsolete.  If @var{current-name} is a symbol, the
+warning message says to use @var{current-name} instead of
+@var{obsolete-name}.  @var{current-name} does not need to be an alias for
+@var{obsolete-name}; it can be a different function with similar
+functionality.  If @var{current-name} is a string, it is the warning
+message.
+
+If provided, @var{when} should be a string indicating when the function
+was first made obsolete---for example, a date or a release number.
+@end defun
+
+You can define a function as an alias and declare it obsolete at the
+same time using the macro @code{define-obsolete-function-alias}.
+
+@defmac define-obsolete-function-alias obsolete-name current-name &optional when docstring
+This macro marks the function @var{obsolete-name} obsolete and also
+defines it as an alias for the function @var{current-name}.  It is
+equivalent to the following:
+
+@example
+(defalias @var{obsolete-name} @var{current-name} @var{docstring})
+(make-obsolete @var{obsolete-name} @var{current-name} @var{when})
+@end example
+@end defmac
+
 @node Inline Functions
 @section Inline Functions
 @cindex inline functions
@@ -1161,17 +1193,22 @@ function except for one thing: when you compile a call to the function,
 the function's definition is open-coded into the caller.
 
 Making a function inline makes explicit calls run faster.  But it also
-has disadvantages.  For one thing, it reduces flexibility; if you change
-the definition of the function, calls already inlined still use the old
-definition until you recompile them.  Since the flexibility of
-redefining functions is an important feature of Emacs, you should not
-make a function inline unless its speed is really crucial.
+has disadvantages.  For one thing, it reduces flexibility; if you
+change the definition of the function, calls already inlined still use
+the old definition until you recompile them.
 
 Another disadvantage is that making a large function inline can increase
 the size of compiled code both in files and in memory.  Since the speed
 advantage of inline functions is greatest for small functions, you
 generally should not make large functions inline.
 
+Also, inline functions do not behave well with respect to debugging,
+tracing, and advising (@pxref{Advising Functions}).  Since ease of
+debugging and the flexibility of redefining functions are important
+features of Emacs, you should not make a function inline, even if it's
+small, unless its speed is really crucial, and you've timed the code
+to verify that using @code{defun} actually has performance problems.
+
 It's possible to define a macro to expand into the same code that an
 inline function would execute.  (@xref{Macros}.)  But the macro would be
 limited to direct use in expressions---a macro cannot be called with
@@ -1186,7 +1223,7 @@ Inline functions can be used and open-coded later on in the same file,
 following the definition, just like macros.
 
 @node Function Safety
-@section Determining whether a function is safe to call
+@section Determining whether a Function is Safe to Call
 @cindex function safety
 @cindex safety of functions