抽象和具体的语法 [英] Abstract and concrete syntax

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

问题描述






我试过python,并且喜欢它。易于学习和阅读(至少对于

常用部分),有一个非常大的社区如此优秀的文档和

贡献,而且......设计很干净。我来自功能性的

编程语言,我喜欢正确的静态绑定,第一个

类函数。这就是我对Python感兴趣的东西。这是令人上瘾的脚本语言中最现代的。



但是,有些东西我不敢相信。陈述不是表达。我想b $ b试图在网上找到一些关于这个的文档。我不满意,而且我想要了解更多并在这里讨论。


首先,有一些关于Python Zen禁止的巨魔陈述是

表达式。但我认为禅宗经常是矛盾的。我不喜欢

巨魔,想要一些严肃的东西。


基本上,我发现一个很好的观点来反对语句 - 表达式:它

不适合缩进敏感语法。


---
http://mail.python.org/pipermail/pyt...ry/260566.html

Python允许在复合

语句中的套件和套件内的语句。它还允许在语句和表达式内部使用表达式

。它永远不会做的一件事是在表达式中允许套件或

语句,因为这样做会完全破坏

处理大量空白区域。

---


我觉得这里有一些真正的问题。但我找不到任何

绝对无法解决的问题。我玩了几个例子,不能得到任何东西

模棱两可。也许嵌套分析仪

http ://python.org/doc/2.4.1/ref/indentation.html )需要考虑

帐户括号内的分隔符以及缩进,但是那个

看起来不可能(虽然我怀疑它比我想象的更难)。

括号诀窍可以避免过度缩进。

set_callback(obj,

lambda x :(如果:

2

否则:

3)


嗯,我怀疑存在一些道德问题,也许pythonists不希望
想要表达语句.PEP#308是关于有一个三元(?:)

运算符用于表达级别的条件,pythonists拒绝了它。我会想要更多地了解投票的动机。


很多人会告诉我,我的小例子可以写成

if-else out理想的分配。我声称能够以你的方式表达

更好。这就是为什么lambda也在这里。


更一般地说,我认为

语句和表达式之间没有抽象的区别。一切都是表达式,可以评估价值。
到一个值。制作功能一流的对象是同样好的

和漂亮的想法。所以如果没有抽象的区别,为什么要有一个具体的呢?如果这只是一个技术问题,那就让我们继续吧。


但是我想你在这个问题上还有更多的话要说...

__

David


Hi,

I tried python, and do like it. Easy to learn and read (at least for the
commonly used part), has a very large community so great doc and
contributions, and... the design is clean. I come from functional
programming languages, and I do like the proper static binding, the first
class functions. That''s what interests me in Python. It''s the most modern
of those addictive scripting languages.

But, there is something I can''t believe. Statements are not expressions. I
tried to find some doc about that on the web. I''m not satisfied, and I''d
like to learn more and discuss here.

First, there are some trolls about Python Zen forbidding statements to be
expressions. But I think the Zen is often contradictory. I don''t like
trolls, want something serious.

Basically, I found one good point against statements-as-expressions: it
cannot fit the indentation sensitive syntax.

---
http://mail.python.org/pipermail/pyt...ry/260566.html
Python allows statements inside suites and suites inside compound
statements. It also allows expressions inside statements and expressions
inside expressions. The one thing it never ever does is allow a suite or a
statement inside an expression, because doing so would utterly destroy the
handling of significant white space.
---

I feel there are some real problems here. But I can''t find anything
absolutely unsolvable. I played a few examples, can''t get anything
ambiguous. Maybe the nesting analyzer
(http://python.org/doc/2.4.1/ref/indentation.html) needs to take into
account parenthesis-like delimiters together with indentation, but that
doesn''t look impossible (although I suspect it''s harder than I can imagine).
The parenthesis trick could avoid over-deep indentation.

set_callback(obj,
lambda x: (if a:
2
else:
3)

Well, I suspect there are some moral issues, and maybe pythonists don''t
want statements in expressions. PEP #308 was about having a ternary (?:)
operator for expression level conditional, pythonists rejected it. I''d
like to read more about the motivations of the vote.

Many people will tell me that my tiny example can be written with the
if-else outside the assignation. I claim it''s better to be able to express
it the way you mean it. That''s why lambda is here for, too.

More generally, I think there is no abstract distinction between
statements and expressions. Everything is an expression, can be evaluated
to a value. Making function first class objects was the same kind of good
and beautiful idea. So if there is no abstract distinction, why should
there be a concrete one? If it''s just a technical issue, let''s work on it.

But I guess you''ll have more to say on that subject...
__
David

推荐答案

" David Baelde" <哒********** @ ens-lyon.fr>在留言中写道

news:pa **************************** @ ens-lyon.fr .. 。
"David Baelde" <da**********@ens-lyon.fr> wrote in message
news:pa****************************@ens-lyon.fr...



我试过python,并且喜欢它。易于学习和阅读(至少对于常用的部分而言),有一个非常大的社区,如此伟大的文档和贡献,以及...设计是干净的。我来自功能性的编程语言,我喜欢正确的静态绑定,第一个类函数。这就是我对Python感兴趣的东西。它是那些令人上瘾的脚本语言中最现代的。

但是,有一些我不能相信的东西。陈述不是表达。我试图在网上找到一些关于这方面的文档。我不满意,而且我想要了解更多并在这里讨论。

首先,有一些关于Python Zen的巨魔禁止陈述是
表达式。但我认为禅宗经常是矛盾的。我不喜欢
巨魔,想要一些严肃的东西。

基本上,我发现了一个反对语句表达的好点:它不适合缩进敏感语法。

---
http://mail.python.org/pipermail/pyt...ry/260566.html
Python允许在复合
语句中的套件和套件内的语句。它还允许在语句和表达式内部表达式内部表达式。它从未做过的一件事就是在表达式中允许使用套件或
语句,因为这样做会完全破坏对重要空白区域的处理。
---

我觉得这里有一些真正的问题。但我找不到任何绝对无法解决的东西。我玩了几个例子,不能得到任何含糊不清的东西。也许是嵌套分析仪
http:// python .org / doc / 2.4.1 / ref / indentation.html )需要将
帐户括号内的分隔符与缩进一起考虑,但这看起来并不可能(尽管看起来不可能)我怀疑它比我想象的更难。
括号诀窍可以避免过度缩进。

set_callback(obj,
lambda x: (如果是:
2
其他:
3)

嗯,我怀疑有一些道德问题,也许pythonists不要
想要表达式中的语句。


有很多方法可以做到;我怀疑BDFL

根本就不想要它。 />
PEP#308是关于有一个三元(?:)
运算符的表达水平条件,pythonists拒绝了它。我想要阅读更多有关动机的信息投票。


好​​吧,Guido从一开始就反对它。他最终决定将b $ b b b用于社区投票,以便对适当的语法进行投票。正如你可以想象的那样,有一个巨大的(好的,几十个)不同的

语法建议,所以实际上不可能获得多数

投票。结果:提案被永久杀害,假装显示了

给了社区一个发言权。


不幸的是,我发现Condorcet的投票太晚了;通过那个

的时间原来的标签不再存在所以他们不能再重新分析。

但是我想你会有更多的东西关于这个问题说...
__
大卫

Hi,

I tried python, and do like it. Easy to learn and read (at least for the
commonly used part), has a very large community so great doc and
contributions, and... the design is clean. I come from functional
programming languages, and I do like the proper static binding, the first
class functions. That''s what interests me in Python. It''s the most modern
of those addictive scripting languages.

But, there is something I can''t believe. Statements are not expressions. I
tried to find some doc about that on the web. I''m not satisfied, and I''d
like to learn more and discuss here.

First, there are some trolls about Python Zen forbidding statements to be
expressions. But I think the Zen is often contradictory. I don''t like
trolls, want something serious.

Basically, I found one good point against statements-as-expressions: it
cannot fit the indentation sensitive syntax.

---
http://mail.python.org/pipermail/pyt...ry/260566.html
Python allows statements inside suites and suites inside compound
statements. It also allows expressions inside statements and expressions
inside expressions. The one thing it never ever does is allow a suite or a
statement inside an expression, because doing so would utterly destroy the
handling of significant white space.
---

I feel there are some real problems here. But I can''t find anything
absolutely unsolvable. I played a few examples, can''t get anything
ambiguous. Maybe the nesting analyzer
(http://python.org/doc/2.4.1/ref/indentation.html) needs to take into
account parenthesis-like delimiters together with indentation, but that
doesn''t look impossible (although I suspect it''s harder than I can
imagine).
The parenthesis trick could avoid over-deep indentation.

set_callback(obj,
lambda x: (if a:
2
else:
3)

Well, I suspect there are some moral issues, and maybe pythonists don''t
want statements in expressions.
There are a number of ways of doing it; I suspect that the BDFL
simply doesn''t want it.
PEP #308 was about having a ternary (?:)
operator for expression level conditional, pythonists rejected it. I''d
like to read more about the motivations of the vote.
Well, Guido has been against it from the start. He finally decided to
put it up to the community to vote on the appropriate syntax. As you
can imagine, there were a huge (well, a couple of dozen) different
syntax suggestions, so it was effectively impossible to get a majority
vote. Result: proposal killed permanently with a sham showing of
giving the community a say in it.

Unfortunately, I found out about Condorcet voting too late; by that
time the original tallies no longer existed so they could not be
reanalyzed.
But I guess you''ll have more to say on that subject...
__
David






David Baelde写道:
David Baelde wrote:
语句不是表达式。

我觉得这里有一些真正的问题。但我找不到任何绝对无法解决的东西。


毫无疑问,这些问题可以在

a技术意义上解决,但真正的问题是

结果代码将是*可读*。 Python的一个主要优点是它的代码通常很容易读取,即使它意味着更加冗长

倍于绝对必要的时间。


我在表达式中看到的所有提议

in Python(并且已经相当在可读性部门发生了一场灾难。

PEP#308是关于有三元(?:)
运算符的表达级条件,pythonists拒绝了。


实际上,真的Guido拒绝了它,因为

Pythonistas未能就语法达成共识,并且他

首先,这个想法并不是很热门。如果他确实想要它,他就会选择一种语法

本人。

更一般地说,我认为没有抽象的区别
语句和表达之间。一切都是表达式,可以评估一个值。
Statements are not expressions.

I feel there are some real problems here. But I can''t find anything
absolutely unsolvable.
There''s no doubt that these problems could be solved in
a technical sense, but the real issue is whether the
resulting code would be *readable*. One of Python''s
major strengths is that its code is usually very easy
to read, even if it means being a bit more verbose at
times than strictly necessary.

All the proposals I''ve seen for statements-in-expressions
in Python (and there have been quite a few) have been a
disaster in the readability department
PEP #308 was about having a ternary (?:)
operator for expression level conditional, pythonists rejected it.
Actually, it was really Guido who rejected it, because
Pythonistas failed to reach a consensus on syntax, and he
wasn''t really hot on the idea in the first place. If he
had really wanted it, he would have just picked a syntax
himself.
More generally, I think there is no abstract distinction between
statements and expressions. Everything is an expression, can be evaluated
to a value.




这在功能语言中是正确的,但Python不是

功能语言。在命令式编程中,通常你只是为了副作用而做一些事情,并且没有明显的价值

返回。在我看来,强迫一切只为概念纯度而返回一个价值是一种人为的。


-

Greg Ewing,计算机科学系,

坎特伯雷大学,

新西兰基督城
http://www.cosc.canterbury.ac.nz/~greg

" Greg Ewing"写道:
"Greg Ewing" wrote:
更一般地说,我认为
语句和表达式之间没有抽象的区别。一切都是表达式,可以评估一个值。
More generally, I think there is no abstract distinction between
statements and expressions. Everything is an expression, can be evaluated
to a value.



这在功能语言中是正确的,但Python不是一种功能语言。在命令式编程中,通常你只是为了副作用而做某事,并且返回没有明显的价值。在我看来,强迫一切只为了概念纯度而返回一个值是一种人为的。



That''s true in a functional language, but Python is not a
functional language. In imperative programming, often you just
do something for its side effect, and there''s no obvious value
to return. Forcing everything to return a value just for the
sake of conceptual purity is an artificiality, in my view.




嗯,我想是什么造成了人为的主观的话,因为IMO表达式和陈述之间的区别是一个更大的人工性。 Python已经使用默认值(None)从可调用函数返回

,那么什么使语句特殊?当然不是

的副作用,因为设置属性的两种等效方式显示:

ax = val#statement

setattr(a, ''x'',val)#表达


乔治



Well, I guess what makes an artificiality is subjective then, because
IMO the distinction between expressions and statements is a bigger
artificiality. Python already uses a default value (None) to return
from a callable, so what makes statements special ? Certainly not the
side effects, as the two equivalent ways to set an attribute show:
a.x = val # statement
setattr(a,''x'',val) # expression

George


这篇关于抽象和具体的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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