拉姆达 [英] lambda

查看:120
本文介绍了拉姆达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么用lambda表单创建的函数不能包含语句?


如何用语句获取未命名的函数?

why functions created with lambda forms cannot contain statements?

how to get unnamed function with statements?

推荐答案

Egor Bolonev写道:
Egor Bolonev wrote:
为什么用lambda表创建的函数不能包含语句?


语法/技术答案:因为lambda是一个表达式并且它不是很明显如何表达''语句内部''的语法应该是


''Python是完美的''答案:如果一个函数包含的表达式多于一个

,那么它的复杂程度足以要求一个名称

如何使用语句获取未命名的函数?
why functions created with lambda forms cannot contain statements?
syntax/technical answer: because lambda is an expression and it is not
obvious how the syntax for ''statement inside expression'' should be

''Python is perfect'' answer: if a function contains more than an
expression, then it''s complex enough to require a name
how to get unnamed function with statements?




你不能。查看有关Smalltalk / Ruby-like块的各种主题以及

最新的关于''where''关键字的建议,以便更改此建议


Daniel



You can''t. See various threads about Smalltalk/Ruby-like blocks and the
recent one about the ''where'' keyword for proposals to change this

Daniel


因为如果需要多行,则需要一个名称。另外,

如果你在这个函数中有多行,你打算怎么计划

如果没有名字引用它?


Tim

2005年1月13日星期四20:53:09 +1000,Egor Bolonev< eb ****** @ mail.ru>写道:
Because if it takes more than a single line it deserves a name. Also,
if you have more than one line in this function, how do you plan to
reference it if not by name?

Tim
On Thu, 13 Jan 2005 20:53:09 +1000, Egor Bolonev <eb******@mail.ru> wrote:
为什么用lambda表单创建的函数不能包含语句?

如何用语句获取未命名的函数?
-
http://mail.python.org/mailman/listinfo/python-list
why functions created with lambda forms cannot contain statements?

how to get unnamed function with statements?
--
http://mail.python.org/mailman/listinfo/python-list



Op 2005-01-13,Tim Leslie schreef< ti ******** @ gmail.com>:
Op 2005-01-13, Tim Leslie schreef <ti********@gmail.com>:
因为如果它需要一行以上就需要一个名字。
Because if it takes more than a single line it deserves a name.




所以,如果我的呼叫表达式超过

一行,我应该将表达式赋值给一个变量,并且

在调用中使用变量?


但是如果我这样做的话那个,人们会告诉我它有多糟糕,因为它会保留对b / b
将阻止垃圾收集器收获的价值的参考

内存。


除了python允许在同一行上有多个语句。


-

Antoon Pardon



So if I have a call with an expression that takes more than
one line, I should assign the expression to a variable and
use the variable in the call?

But wait if I do that, people will tell me how bad that it
is, because it will keep a reference to the value which
will prevent the garbage collector from harvesting this
memory.

Besides python allows more than one statement on the same line.

--
Antoon Pardon


这篇关于拉姆达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆