[Python-ideas] Syntax: 'return: ...' expressions

Yawar Amin yawar.amin at gmail.com
Tue Jan 6 02:59:20 CET 2015

On 2015-01-05 04:49, Andrew Barnert wrote:
> ... paren continuation just concatenates the lines together.

I'll quote this first, because it's the crux of the matter and what I
failed to understand up until now. IIUC now, Python never actually
'relaxes' any indentation rules--a preprocessor just concatenates split
lines (i.e. lines split with parens etc.) and then passes the result on
to the parser?

I guess pretty much everything else is made redundant by this one point.

> ... I'm not sure what the return adds to it that you couldn't get just
> from brace syntax.

I was trying to avoid brace syntax as un-Pythonic.

> You also seem to have invented a rule that a sequence of statements
> has the value of the last statement as its value. Which requires first
> inventing a rule that gives values to statements. I'll assume you
> wanted to go with the same rule the interactive interpreter uses to
> display a last value--an expression statement has its expression's
> value, and any other kind of statement has None?)

No, I was trying to say that whatever's inside the 'return: ...' block
is evaluated, and then the last expression inside the block becomes the
value of the block as a whole. No change would be required to any
existing expressions or statements, or to the result of a normal
sequence of statements.

> Finally, are you sure your new return: isn't ambiguous without look
> ahead or context? When the parser reads "if spam: return", is it
> starting a return simple statement, or an expression statement that
> starts with a return expression? Have you tried actually writing out
> the grammar?

Having the keyword be 'return' wasn't important to me; it could just as
easily be a new one like 'do' or 'begin'.

It's back to the drawing board for me, I guess :-)



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150105/a4f8c0c6/attachment.sig>

More information about the Python-ideas mailing list