未来更好的lambda支持? [英] better lambda support in the future?

查看:52
本文介绍了未来更好的lambda支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么python仍然有限的lambda支持。什么是
阻止python的开发人员支持更多类似lisp的lambda函数?

解决方案

Lambda函数将在最近的将来成为obsolette。这是

计划。


Jason Zheng写道:

我想知道为什么python仍然有限的lambda支持。是什么阻止python的开发人员支持更多类似lisp的lambda
函数?




每隔几周就出现一次名单。如果你还没有,

检查谷歌档案中的匿名def或匿名

功能。通常对这个问题的回答是

行中的如果它足够好来创建一个函数,那就足够好了

到名称"


此类提案的其他一大原因从来没有成功

远,到目前为止,还没有人找到语法每个人(甚至大多数人都是b $ b)都喜欢。你得到的结果如下:


x = func或lambda x,y:

#lambda func的主体

#indented这里





x = func或lambda x,y:

#body of lambda func

#缩进这里





x = func或lambda x,y {

# lamda func的主体缩进

#但是你想要...

}


或其他任何千种品种。


即使你能解决语法问题,一旦你确定你确实需要一个匿名函数中的真正块,你就不会真的

通过不声明来节省大量空间:


def f(* args):

#body line 1

#body line 2

#...

#body line N

x = func或f


vs


x = func或lambda * args:

#body line 1

#body第2行

#...

#body line N


所以,你保存一行,这只是你的

函数大小的1 N(其中N是函数体中的行数) )。对于

单线或双线功能,这些节省可能更大,

但是如果你的功能只有一两行,它可能是

无论如何写成表达式(例如使用LC或GE)......

检查档案 - 关于这个主题有很多讨论,

但希望上面的简短评论会给你一些

概述。


Steve


< blockquote> Steven Bethard写道:

即使您能解决语法问题,一旦您确定在匿名函数中确实需要一个真正的
块,你并没有真正节省太多空间而没有宣布它:

def f(* args):
#body line 1
#body line 2
# ......
#body line N
x = func或f



x = func或lambda * args:
#体线1
#体线2
#...
#body line N




你的意思是:


def x (* args):

#body line 1

#body line 2

#...

#身体线条N


vs


x = func或lambda * args:

#body line 1

#body line 2

#...

#body line N


对吧?


< / F>


I''m wondering why python still has limited lambda support. What''s
stopping the developers of python to support more lisp-like lambda function?

解决方案

Lambda functions will become obsolette in the nearest future. This is
the PLAN.


Jason Zheng wrote:

I''m wondering why python still has limited lambda support. What''s
stopping the developers of python to support more lisp-like lambda
function?



This comes up every few weeks on the list. If you haven''t already,
check the archives in Google for ''anonymous def'' or ''anonymous
function''. The usual response to this question is something along the
lines of "if it''s good enough to create a function for, it''s good enough
to name".

One of the other big reasons for this type of proposal never making it
far is that, so far, no one has found a syntax that everyone (or even
most people) like. You end up with things like:

x = func or lambda x, y:
# body of lambda func
# indented here

or

x = func or lambda x, y:
# body of lambda func
# indented here

or

x = func or lambda x, y {
# body of lamda func indented
# however you want...
}

or any thousand other varieties.

Even if you could settle the syntax issue, once you''ve decided that you
really do need a true block in an anonymous function, you''re not really
saving much space by not declaring it:

def f(*args):
# body line 1
# body line 2
# ...
# body line N
x = func or f

v.s.

x = func or lambda *args:
# body line 1
# body line 2
# ...
# body line N

so, you save a single line, which is only 1 Nth of the size of your
function (where N is the number of lines in your function body). For a
single or double line function, these savings may be more substantial,
but chances are if your function is only one or two lines, it can be
written as an expression anyway (e.g. using LCs or GEs)...
Do check the archives -- there are a lot of discussions on this topic,
but hopefully the brief commentary above will give you something of an
overview.

Steve


Steven Bethard wrote:

Even if you could settle the syntax issue, once you''ve decided that you really do need a true
block in an anonymous function, you''re not really saving much space by not declaring it:

def f(*args):
# body line 1
# body line 2
# ...
# body line N
x = func or f

v.s.

x = func or lambda *args:
# body line 1
# body line 2
# ...
# body line N



you meant:

def x(*args):
# body line 1
# body line 2
# ...
# body line N

v.s.

x = func or lambda *args:
# body line 1
# body line 2
# ...
# body line N

right?

</F>


这篇关于未来更好的lambda支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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