emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/doc/lispref ChangeLog functions.texi


From: Chong Yidong
Subject: [Emacs-diffs] emacs/doc/lispref ChangeLog functions.texi
Date: Sun, 13 Sep 2009 01:47:04 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Chong Yidong <cyd>      09/09/13 01:47:04

Modified files:
        doc/lispref    : ChangeLog functions.texi 

Log message:
        * functions.texi (Anonymous Functions): Rearrange discussion,
        giving usage of unquoted lambda forms first.  Mention that
        `function' and `#'' are no longer required (Bug#4290).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/doc/lispref/ChangeLog?cvsroot=emacs&r1=1.324&r2=1.325
http://cvs.savannah.gnu.org/viewcvs/emacs/doc/lispref/functions.texi?cvsroot=emacs&r1=1.19&r2=1.20

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/doc/lispref/ChangeLog,v
retrieving revision 1.324
retrieving revision 1.325
diff -u -b -r1.324 -r1.325
--- ChangeLog   11 Sep 2009 20:26:50 -0000      1.324
+++ ChangeLog   13 Sep 2009 01:47:03 -0000      1.325
@@ -1,3 +1,9 @@
+2009-09-13  Chong Yidong  <address@hidden>
+
+       * functions.texi (Anonymous Functions): Rearrange discussion,
+       giving usage of unquoted lambda forms first.  Mention that
+       `function' and `#'' are no longer required (Bug#4290).
+
 2009-09-11  Alan Mackenzie  <address@hidden>
 
        * os.texi (Terminal Output): document `send-string-to-terminal' in

Index: functions.texi
===================================================================
RCS file: /sources/emacs/emacs/doc/lispref/functions.texi,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- functions.texi      9 Jul 2009 03:05:35 -0000       1.19
+++ functions.texi      13 Sep 2009 01:47:04 -0000      1.20
@@ -887,9 +887,9 @@
 
   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
-are defined with @code{defun} and given names at the same time, it is
-occasionally more concise to use an explicit lambda expression---an
+primitive subr-object; names are ``extra.''  Although functions are
+usually 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.
 
   Any method of creating such a list makes a valid function.  Even this:
@@ -916,17 +916,21 @@
 @end example
 
 @noindent
-(It does @emph{not} work to write @code{(silly 1)}, because this function
-is not the @emph{function definition} of @code{silly}.  We have not given
address@hidden any function definition, just a value as a variable.)
+It does @emph{not} work to write @code{(silly 1)}, because this
+function is not the @emph{function definition} of @code{silly}.  We
+have not given @code{silly} any function definition, just a value as a
+variable.
 
   Most of the time, anonymous functions are constants that appear in
-your program.  For example, you might want to pass one as an argument to
-the function @code{mapcar}, which applies any given function to each
-element of a list.
-
-  Here we define a function @code{change-property} which
-uses a function as its third argument:
+your program.  For instance, you might want to pass one as an argument
+to the function @code{mapcar}, which applies any given function to
+each element of a list (@pxref{Mapping Functions}).
address@hidden example}, for a realistic example of this.
+
+  In the following example, we define a @code{change-property}
+function that takes a function as its third argument, followed by a
address@hidden function that makes use of
address@hidden by passing it an anonymous function:
 
 @example
 @group
@@ -934,61 +938,71 @@
   (let ((value (get symbol prop)))
     (put symbol prop (funcall function value))))
 @end group
address@hidden example
-
address@hidden
-Here we define a function that uses @code{change-property},
-passing it a function to double a number:
 
address@hidden
 @group
 (defun double-property (symbol prop)
-  (change-property symbol prop '(lambda (x) (* 2 x))))
+  (change-property symbol prop (lambda (x) (* 2 x))))
 @end group
 @end example
 
 @noindent
-In such cases, we usually use the special form @code{function} instead
-of simple quotation to quote the anonymous function, like this:
+In the @code{double-property} function, we did not quote the
address@hidden form.  This is permissible, because a @code{lambda} form
+is @dfn{self-quoting}: evaluating the form yields the form itself.
+
+Whether or not you quote a @code{lambda} form makes a difference if
+you compile the code (@pxref{Byte Compilation}).  If the @code{lambda}
+form is unquoted, as in the above example, the anonymous function is
+also compiled.  Suppose, however, that we quoted the @code{lambda}
+form:
 
 @example
 @group
 (defun double-property (symbol prop)
-  (change-property symbol prop
-                   (function (lambda (x) (* 2 x)))))
+  (change-property symbol prop '(lambda (x) (* 2 x))))
 @end group
 @end example
 
-Using @code{function} instead of @code{quote} makes a difference if you
-compile the function @code{double-property}.  For example, if you
-compile the second definition of @code{double-property}, the anonymous
-function is compiled as well.  By contrast, if you compile the first
-definition which uses ordinary @code{quote}, the argument passed to
address@hidden is the precise list shown:
address@hidden
+If you compile this, the argument passed to @code{change-property} is
+the precise list shown:
 
 @example
 (lambda (x) (* x 2))
 @end example
 
 @noindent
-The Lisp compiler cannot assume this list is a function, even though it
-looks like one, since it does not know what @code{change-property} will
-do with the list.  Perhaps it will check whether the @sc{car} of the third
-element is the symbol @code{*}!  Using @code{function} tells the
-compiler it is safe to go ahead and compile the constant function.
+The Lisp compiler cannot assume this list is a function, even though
+it looks like one, since it does not know what @code{change-property}
+will do with the list.  Perhaps it will check whether the @sc{car} of
+the third element is the symbol @code{*}!
+
address@hidden function
+The @code{function} special form explicitly tells the byte-compiler
+that its argument is a function:
 
-  Nowadays it is possible to omit @code{function} entirely, like this:
address@hidden function function-object
address@hidden function quoting
+This special form returns @var{function-object} without evaluating it.
+In this, it is equivalent to @code{quote}.  However, it serves as a
+note to the Emacs Lisp compiler that @var{function-object} is intended
+to be used only as a function, and therefore can safely be compiled.
+Contrast this with @code{quote}, in @ref{Quoting}.
address@hidden defspec
+
address@hidden @samp{#'} syntax
+The read syntax @code{#'} is a short-hand for using @code{function}.
+Generally, it is not necessary to use either @code{#'} or
address@hidden; just use an unquoted @code{lambda} form instead.
+(Actually, @code{lambda} is a macro defined using @code{function}.)
+The following forms are all equivalent:
 
 @example
address@hidden
-(defun double-property (symbol prop)
-  (change-property symbol prop (lambda (x) (* 2 x))))
address@hidden group
+#'(lambda (x) (* x x))
+(function (lambda (x) (* x x)))
+(lambda (x) (* x x))
 @end example
 
address@hidden
-This is because @code{lambda} itself implies @code{function}.
-
   We sometimes write @code{function} instead of @code{quote} when
 quoting the name of a function, but this usage is just a sort of
 comment:
@@ -997,33 +1011,6 @@
 (function @var{symbol}) @equiv{} (quote @var{symbol}) @equiv{} '@var{symbol}
 @end example
 
address@hidden @samp{#'} syntax
-  The read syntax @code{#'} is a short-hand for using @code{function}.
-For example,
-
address@hidden
-#'(lambda (x) (* x x))
address@hidden example
-
address@hidden
-is equivalent to
-
address@hidden
-(function (lambda (x) (* x x)))
address@hidden example
-
address@hidden function function-object
address@hidden function quoting
-This special form returns @var{function-object} without evaluating it.
-In this, it is equivalent to @code{quote}.  However, it serves as a
-note to the Emacs Lisp compiler that @var{function-object} is intended
-to be used only as a function, and therefore can safely be compiled.
-Contrast this with @code{quote}, in @ref{Quoting}.
address@hidden defspec
-
-  @xref{describe-symbols example}, for a realistic example using
address@hidden and an anonymous function.
-
 @node Function Cells
 @section Accessing Function Cell Contents
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]