#python #sicp
we can compute a*b + c*d without
having to name the subexpressions a*b or c*d , or the full expression.
In Python, we can create function values on the fly using lambda expressions, which evaluate to unnamed functions. A lambda expression evaluates
to a function that has a single return expression as its body. Assignment and
control statements are not allowed.
If you want to change selection, open document below and click on "Move attachment"
1.6 Higher-Order Functions
1.6.7 Lambda Expressions
Video:
Show
Hide So far, each time we have wanted to define a new function, we needed to give it
a name. But for other types of expressions, we don't need to associate
intermediate values with a name. That is, <span>we can compute a*b + c*d without
having to name the subexpressions a*b or c*d , or the full expression.
In Python, we can create function values on the fly using lambda
expressions, which evaluate to unnamed functions. A lambda expression evaluates
to a function that has a single return expression as its body. Assignment and
control statements are not allowed.
>>> def compose1(f, g):
return lambda x: f(g(x))
We can understand the structure of a lambda expression by constructing a
corresponding English sentence:
Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details