在Python中保护匿名函数的未来 [英] Securing a future for anonymous functions in Python

查看:81
本文介绍了在Python中保护匿名函数的未来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GvR评论说他想摆脱Python 3.0的lambda关键字。

摆脱lambda似乎是一个有价值的目标,但我更愿意看到它掉线了/>
支持不同的语法,而不是完全失去

具有匿名功能的能力。


无论如何,我是寻找有关基于def的语法的反馈,该语法出现在最近的讨论中:

clp讨论:
http://boredomandlaziness.skystorm.n...in-python.html


干杯,

尼克。


-

Nick Coghlan | nc******@email.com |澳大利亚布里斯班

--------------------------------------- ------------------------
http://boredomandlaziness.skystorm.net

GvR has commented that he want to get rid of the lambda keyword for Python 3.0.
Getting rid of lambda seems like a worthy goal, but I''d prefer to see it dropped
in favour of a different syntax, rather than completely losing the ability to
have anonymous functions.

Anyway, I''m looking for feedback on a def-based syntax that came up in a recent
c.l.p discussion:
http://boredomandlaziness.skystorm.n...in-python.html

Cheers,
Nick.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net

推荐答案

Nick Coghlan< nc ****** @ iinet.net.au>写道:
Nick Coghlan <nc******@iinet.net.au> writes:
无论如何,我正在寻找有关基于def语法的反馈,该语法出现在最近的clp讨论中:
Anyway, I''m looking for feedback on a def-based syntax that came up in
a recent c.l.p discussion:




看起来只是一个更加扭曲的lambda版本。它没有
修复lambda的主要缺陷,即无法在匿名函数中有几个

语句。



Looks like just an even more contorted version of lambda. It doesn''t
fix lambda''s main deficiency which is inability to have several
statements in the anonymous function.


Paul Rubin写道:
Paul Rubin wrote:
Nick Coghlan< nc ****** @ iinet.net.au>写道:
Nick Coghlan <nc******@iinet.net.au> writes:
无论如何,我正在寻找有关基于def语法的反馈,该语法出现在最近的clp讨论中:
Anyway, I''m looking for feedback on a def-based syntax that came up in
a recent c.l.p discussion:



看起来只是一个更加扭曲的lambda版本。它没有解决lambda的主要缺陷,即无法在匿名函数中有几个
语句。


Looks like just an even more contorted version of lambda. It doesn''t
fix lambda''s main deficiency which is inability to have several
statements in the anonymous function.




你呢考虑生成器表达式或列表推导不足,因为

他们不允许for循环体中的几个语句?


干杯,

尼克。


-

Nick Coghlan | nc******@email.com |澳大利亚布里斯班

--------------------------------------- ------------------------
http://boredomandlaziness.skystorm.net



Do you consider generator expressions or list comprehensions deficient because
they don''t allow several statements in the body of the for loop?

Cheers,
Nick.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net




" Nick Coghlan" <数控****** @ iinet.net.au>在留言中写道

新闻:ma ************************************ ** @ pyth on.org ...

"Nick Coghlan" <nc******@iinet.net.au> wrote in message
news:ma**************************************@pyth on.org...
GvR评论说他想摆脱Python的lambda关键字
3.0。摆脱lambda似乎是一个有价值的目标,但我更愿意看到它倾向于采用不同的语法,而不是完全丧失具有匿名功能的能力。

无论如何,我正在寻找有关基于def语法的反馈,该语法出现在最近的clp讨论中:
http://boredomandlaziness.skystorm.n...in-python.html

欢呼,
尼克。


我认为这是相当巴洛克式的,我同意Paul Ruben

它需要多种声明能力。


我更喜欢的语法(我不知道它之前是否实际上是

)是使用大括号,即{和}。


换句话说,匿名函数如下:

{p1,p2,p3 |

stmt1

stmt2

}


使用大括号有两个原因。一个是

,这是大量语言块的常用语法。另一个是它应该是相对的

很容易从字典文字中消除歧义,这是目前唯一使用大括号的美元。


参数列表是可选的,列表结尾的栏是

。 bar的原因而不是冒号

是在单个参数的情况下帮助解析器,

这看起来像是字典的开头
literal。如果解析器不需要帮助,那么冒号

将更加一致,因此更好。


第二个问题是缩进。我会设置缩进

边界,无论构造的_second_行是什么,b $ b开始,只要它在前面的右边

缩进边界。这个不幸的部分,以及其中一个主要的绊脚石,就是它可能需要一些

重要的词法分析器和解析器,

目前还没有设置从表达式转换回语句模式然后返回表达式

模式。


John Roth

-
Nick Coghlan | nc******@email.com |澳大利亚布里斯班
------------------------------------------- --------------------
http://boredomandlaziness.skystorm.net
GvR has commented that he want to get rid of the lambda keyword for Python
3.0. Getting rid of lambda seems like a worthy goal, but I''d prefer to see
it dropped in favour of a different syntax, rather than completely losing
the ability to have anonymous functions.

Anyway, I''m looking for feedback on a def-based syntax that came up in a
recent c.l.p discussion:
http://boredomandlaziness.skystorm.n...in-python.html

Cheers,
Nick.
I think it''s rather baroque, and I agree with Paul Ruben
that it needs multiple statement capability.

The syntax I prefer (and I don''t know if it''s actually been
suggested before) is to use braces, that is { and }.

In other words, an anonymous function looks like:
{p1, p2, p3 |
stmt1
stmt2
}

There are two reasons for using braces. One is
that it''s the common syntax for blocks in a large number
of languages. The other is that it should be relatively
easy to disambiguate from dictionary literals, which are
the only other current use of braces.

The parameter list is optional, as is the bar ending
the list. The reason for the bar instead of a colon
is to help the parser in the case of a single parameter,
which would look like the beginning of a dictionary
literal. If the parser doesn''t need the help, then a colon
would be more consistent, hence better.

A second issue is indentation. I''d set the indentation
boundary wherever the _second_ line of the construct
starts, as long as it''s to the right of the prior
indentation boundary. The unfortunate part of this, and one of the
major stumbling blocks, is that it might take some
significant reconceptualizing of the lexer and parser,
which currently isn''t set up to shift from expression
back to statement mode and then return to expression
mode.

John Roth
--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net






这篇关于在Python中保护匿名函数的未来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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