[Python-Dev] exec/with thunk-handling proposal

holger krekel pyth@devel.trillke.net
Tue, 4 Feb 2003 15:08:51 +0100


Jack Jansen wrote:
> 
> 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".

I am a bit wary about all those syntax details.  Actually i try
to focus on which events an 'execution monitor' should handle
and how it interacts.  The problem is that talking about
new semantics immeditately brings up the question of syntax
and then everybody discusses syntax. 

> 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():

Yes, but names are important and 

    exec autoclose with f1=open(inputfn):
        ...

is not that hard to read and understand.  I'd even dare to say
it's easier than understanding metaclasses :-)

Also today 'exec' is hardly ever needed and so reinterpreting 
it in the long run might be viable.  "Oh yes, i forgot to tell,
you can also pass it a string or a code object ..."

> 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

Isn't that a road to macros? :-)

I don't know but it sure reduces readability and it looks like cheating. 
we don't want to introduce new keywords, anyway.  To me it is not
only a matter of 'syntax' problems or beeing backward-incompatible 
but the real problem is the number of concepts and constructs you
have to remember, to understand, to use and to teach. 

    holger