[Python-Dev] exec/with thunk-handling proposal
Jack Jansen
Jack.Jansen@cwi.nl
Tue, 4 Feb 2003 14:37:56 +0100
On Tuesday, Feb 4, 2003, at 12:54 Europe/Amsterdam, holger krekel wrote:
>>> exec expr [with params]: suite
>>
>> Gut reaction: ugh!
>
> then i guess you rather prefer new keywords. I thought that there
> is a general reluctance to introduce new keywords *and* many
> people dislike 'exec' for its existence.
I agree with Michael's "Ugh!". And actually I extend the "Ugh!" to
Guido's proposal
of "expr [= expr] [lambda]: suite".
While I think that the reluctance to introduce new keywords is a good
thing in principle
it shouldn't go at the expense of the clarity of the language. In other
words, if there
is a clear construct that doesn't require a new keyword (cf. import as)
that is a good thing,
but if the clarity of Python would be compromised then I think we
should bite the bullet
and add a new keyword.
We should think of people who come fresh to Python in three years time.
What "if" does
and what the parameters are is immediately clear. Same for "for". Same
for "class", "def",
assignments and what-have-you. And then suddenly they come across
foo():
...
or
exec foo():
...
The only construct I can think of that would give the user an idea of
what was happening is
"with expr [= expr]". And even that will become ugly once you want to
support both thunks
with a new scope and parameters, and thunks in the existing scope.
Last week I made a suggestion that was completely ignored, so let me
try again (i.e. if everyone thinks
it's silly please shoot it down in stead of ignoring it:-): how about
adding a meta-keyword
that would be used to turn an identifier into a keyword. For sake of
the example let's use
"keyword" as the meta-keyword, although that's a bad choice, probably.
Here's how it would be
used: if we decide to go with "with" as the thunk-keyword what happens
is that in Python 2.4
you would have to type it as
keyword(with) expr:
suite
or, alternatively, do something like "from future import with_keyword".
In 2.4, using "with" as an identifier
would give a FutureWarning. In Python 2.5 "with" would become a
reserved word, but keyword(with) would
still continue to work. Whether the latter is for one release (with
accompanying FutureWarning) or
for all eternity is open to discussion.
--
Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma
Goldman