[Python-ideas] Syntax: 'return: ...' expressions
yawar.amin at gmail.com
Wed Jan 7 03:08:46 CET 2015
On 2015-01-06 03:25, Andrew Barnert wrote:
> I think you're missing another important point here: statements and
> expressions are different things. Blocks are made up of statements,
> not expressions, ...
Actually I can offer counter-examples to that:
def p(x): print x
class A: p("Hello!")
class B: 1
But I think I see what's happening here: statements are the top dogs in
Python, and when Python wants a statement but only has an expression, it
'promotes' the expression into a statement by evaluating it, throwing
away its value, and pretending nothing happened (i.e., that there was a
'pass' statement there). Thus defining a class can have the nonsensical
effect of calling a function.
But there's currently no way of going in the other direction, i.e.
demoting a statement to an expression. Which is what I was trying to do.
I _still_ think at least something like the following would work (in
terms of Python's grammar):
expr_expr: 'expr' ':' small_stmt (';' small_stmt)* [';' expr]
x = expr: import os; os.system("date")
I'll explore this further and see where it goes.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 834 bytes
Desc: OpenPGP digital signature
More information about the Python-ideas