[Python-checkins] python/dist/src/Doc/ref ref5.tex,1.53.4.5,1.53.4.6
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
2002年6月24日 21:00:26 -0700
Update of /cvsroot/python/python/dist/src/Doc/ref
In directory usw-pr-cvs1:/tmp/cvs-serv13367
Modified Files:
Tag: release22-maint
ref5.tex
Log Message:
Backport change to 1.58 giving Lambda a separate section.
Index: ref5.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref5.tex,v
retrieving revision 1.53.4.5
retrieving revision 1.53.4.6
diff -C2 -d -r1.53.4.5 -r1.53.4.6
*** ref5.tex 30 Apr 2002 02:21:32 -0000 1.53.4.5
--- ref5.tex 25 Jun 2002 04:00:24 -0000 1.53.4.6
***************
*** 974,982 ****
not \code{''}.)
Lambda forms (lambda expressions) have the same syntactic position as
expressions. They are a shorthand to create anonymous functions; the
expression \code{lambda \var{arguments}: \var{expression}}
! yields a function object that behaves virtually identical to one
! defined with
\begin{verbatim}
--- 974,987 ----
not \code{''}.)
+ \section{Lambdas\label{lambdas}}
+ \indexii{lambda}{expression}
+ \indexii{lambda}{form}
+ \indexii{anonmymous}{function}
+
Lambda forms (lambda expressions) have the same syntactic position as
expressions. They are a shorthand to create anonymous functions; the
expression \code{lambda \var{arguments}: \var{expression}}
! yields a function object. The unnamed object behaves like a function
! object defined with
\begin{verbatim}
***************
*** 988,1019 ****
that functions created with lambda forms cannot contain statements.
\label{lambda}
- \indexii{lambda}{expression}
- \indexii{lambda}{form}
- \indexii{anonmymous}{function}
-
- \strong{Programmer's note:} Prior to Python 2.1, a lambda form defined
- inside a function has no access to names defined in the function's
- namespace. This is because Python had only two scopes: local and
- global. A common work-around was to use default argument values to
- pass selected variables into the lambda's namespace, e.g.:
-
- \begin{verbatim}
- def make_incrementor(increment):
- return lambda x, n=increment: x+n
- \end{verbatim}
-
- As of Python 2.1, nested scopes were introduced, and this work-around
- has not been necessary. Python 2.1 supports nested scopes in modules
- which include the statement \samp{from __future__ import
- nested_scopes}, and more recent versions of Python enable nested
- scopes by default. This version works starting with Python 2.1:
-
- \begin{verbatim}
- from __future__ import nested_scopes
-
- def make_incrementor(increment):
- return lambda x: x+increment
- \end{verbatim}
-
\section{Expression lists\label{exprlists}}
--- 993,996 ----