Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b8f89357
Commit
b8f89357
authored
Oct 06, 2013
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use "lambda expression" as preferred to "lambda form".
parent
e4feff1d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
17 deletions
+18
-17
Doc/faq/design.rst
Doc/faq/design.rst
+5
-5
Doc/reference/compound_stmts.rst
Doc/reference/compound_stmts.rst
+5
-5
Doc/reference/expressions.rst
Doc/reference/expressions.rst
+7
-6
Doc/tutorial/controlflow.rst
Doc/tutorial/controlflow.rst
+1
-1
No files found.
Doc/faq/design.rst
View file @
b8f89357
...
@@ -347,20 +347,20 @@ Answer 2: Fortunately, there is `Stackless Python <http://www.stackless.com>`_,
...
@@ -347,20 +347,20 @@ Answer 2: Fortunately, there is `Stackless Python <http://www.stackless.com>`_,
which has a completely redesigned interpreter loop that avoids the C stack.
which has a completely redesigned interpreter loop that avoids the C stack.
Why can't lambda
form
s contain statements?
Why can't lambda
expression
s contain statements?
------------------------------------------
------------------------------------------
------
Python lambda
form
s cannot contain statements because Python's syntactic
Python lambda
expression
s cannot contain statements because Python's syntactic
framework can't handle statements nested inside expressions. However, in
framework can't handle statements nested inside expressions. However, in
Python, this is not a serious problem. Unlike lambda forms in other languages,
Python, this is not a serious problem. Unlike lambda forms in other languages,
where they add functionality, Python lambdas are only a shorthand notation if
where they add functionality, Python lambdas are only a shorthand notation if
you're too lazy to define a function.
you're too lazy to define a function.
Functions are already first class objects in Python, and can be declared in a
Functions are already first class objects in Python, and can be declared in a
local scope. Therefore the only advantage of using a lambda
form
instead of a
local scope. Therefore the only advantage of using a lambda instead of a
locally-defined function is that you don't need to invent a name for the
locally-defined function is that you don't need to invent a name for the
function -- but that's just a local variable to which the function object (which
function -- but that's just a local variable to which the function object (which
is exactly the same type of object that a lambda
form
yields) is assigned!
is exactly the same type of object that a lambda
expression
yields) is assigned!
Can Python be compiled to machine code, C or some other language?
Can Python be compiled to machine code, C or some other language?
...
...
Doc/reference/compound_stmts.rst
View file @
b8f89357
...
@@ -535,17 +535,17 @@ function. The annotation values are available as values of a dictionary keyed
...
@@ -535,17 +535,17 @@ function. The annotation values are available as values of a dictionary keyed
by the parameters' names in the :attr:`__annotations__` attribute of the
by the parameters' names in the :attr:`__annotations__` attribute of the
function object.
function object.
.. index:: pair: lambda;
form
.. index:: pair: lambda;
expression
It is also possible to create anonymous functions (functions not bound to a
It is also possible to create anonymous functions (functions not bound to a
name), for immediate use in expressions. This uses lambda
form
s, described in
name), for immediate use in expressions. This uses lambda
expression
s, described in
section :ref:`lambda`. Note that the lambda
form
is merely a shorthand for a
section :ref:`lambda`. Note that the lambda
expression
is merely a shorthand for a
simplified function definition; a function defined in a ":keyword:`def`"
simplified function definition; a function defined in a ":keyword:`def`"
statement can be passed around or assigned to another name just like a function
statement can be passed around or assigned to another name just like a function
defined by a lambda
form
. The ":keyword:`def`" form is actually more powerful
defined by a lambda
expression
. The ":keyword:`def`" form is actually more powerful
since it allows the execution of multiple statements and annotations.
since it allows the execution of multiple statements and annotations.
**Programmer's note:** Functions are first-class objects. A "``def``"
form
**Programmer's note:** Functions are first-class objects. A "``def``"
statement
executed inside a function definition defines a local function that can be
executed inside a function definition defines a local function that can be
returned or passed around. Free variables used in the nested function can
returned or passed around. Free variables used in the nested function can
access the local variables of the function containing the def. See section
access the local variables of the function containing the def. See section
...
...
Doc/reference/expressions.rst
View file @
b8f89357
...
@@ -1218,8 +1218,8 @@ Conditional expressions
...
@@ -1218,8 +1218,8 @@ Conditional expressions
.. productionlist::
.. productionlist::
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
expression: `conditional_expression` | `lambda_
form
`
expression: `conditional_expression` | `lambda_
expr
`
expression_nocond: `or_test` | `lambda_
form
_nocond`
expression_nocond: `or_test` | `lambda_
expr
_nocond`
Conditional expressions (sometimes called a "ternary operator") have the lowest
Conditional expressions (sometimes called a "ternary operator") have the lowest
priority of all Python operations.
priority of all Python operations.
...
@@ -1243,10 +1243,10 @@ Lambdas
...
@@ -1243,10 +1243,10 @@ Lambdas
pair: anonymous; function
pair: anonymous; function
.. productionlist::
.. productionlist::
lambda_
form
: "lambda" [`parameter_list`]: `expression`
lambda_
expr
: "lambda" [`parameter_list`]: `expression`
lambda_
form
_nocond: "lambda" [`parameter_list`]: `expression_nocond`
lambda_
expr
_nocond: "lambda" [`parameter_list`]: `expression_nocond`
Lambda
forms (lambda expression
s) have the same syntactic position as
Lambda
expressions (sometimes called lambda form
s) have the same syntactic position as
expressions. They are a shorthand to create anonymous functions; the expression
expressions. They are a shorthand to create anonymous functions; the expression
``lambda arguments: expression`` yields a function object. The unnamed object
``lambda arguments: expression`` yields a function object. The unnamed object
behaves like a function object defined with ::
behaves like a function object defined with ::
...
@@ -1255,7 +1255,8 @@ behaves like a function object defined with ::
...
@@ -1255,7 +1255,8 @@ behaves like a function object defined with ::
return expression
return expression
See section :ref:`function` for the syntax of parameter lists. Note that
See section :ref:`function` for the syntax of parameter lists. Note that
functions created with lambda forms cannot contain statements or annotations.
functions created with lambda expressions cannot contain statements or
annotations.
.. _exprlists:
.. _exprlists:
...
...
Doc/tutorial/controlflow.rst
View file @
b8f89357
...
@@ -588,7 +588,7 @@ Lambda Expressions
...
@@ -588,7 +588,7 @@ Lambda Expressions
Small anonymous functions can be created with the :keyword:`lambda` keyword.
Small anonymous functions can be created with the :keyword:`lambda` keyword.
This function returns the sum of its two arguments: ``lambda a, b: a+b``.
This function returns the sum of its two arguments: ``lambda a, b: a+b``.
Lambda f
orm
s can be used wherever function objects are required. They are
Lambda f
unction
s can be used wherever function objects are required. They are
syntactically restricted to a single expression. Semantically, they are just
syntactically restricted to a single expression. Semantically, they are just
syntactic sugar for a normal function definition. Like nested function
syntactic sugar for a normal function definition. Like nested function
definitions, lambda functions can reference variables from the containing
definitions, lambda functions can reference variables from the containing
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment