[Python-ideas] Anonymous blocks (again):
Stephen J. Turnbull
stephen at xemacs.org
Mon May 13 04:53:55 CEST 2013
Martin Morrison writes:
> That is instead of a decorator-like syntax, make the "in" keyword
> reusable to introduce a new block, whose "argument" is a statement
> that can forward reference some names, which are then defined
> within the block. This allows multiple temporary names to be
> defined (each in a separate statement within the block).
This idea and its presumed defects are described (using the "given"
syntax of PEP 3150) in the section "Using a nested suite" in PEP 403.
> Some further thought is required on whether only def (and maybe
> class) statements should be allowed within the "in" block. Although
> I guess there's technically nothing wrong with:
>
> in x = y + z:
> y = 12
> z = 30
>
> Other than it's a very verbose way of doing something simple. ;-)
Violates TOOWTDI according to PEP 403.
David Mertz and Juancarlo Añez riff on the theme:
>[Why not spell it something like]:
>
> in x = do_something(in_arg, success_hdlr, error_hdlr, const) let:
> def success_hdlr(result):
> ... # Do something with result
> def error_hdlr(error):
> ... # Do something with error
> const = 42
(Note the "let" at the end of the "in" clause.)
Python doesn't use redundant keywords for a single construct.
"let" is redundant with the following "def"s. On top of that, "let"
being a new keyword will kill this syntax, I think.
More information about the Python-ideas
mailing list