Thoughts on new grammar rules (PEP 284 in particular)

holger krekel pyth at devel.trillke.net
Fri May 10 13:32:17 EDT 2002


Steve Horne wrote:
> 
> I was just reading PEP284 and, in general, I like it. The trouble is,
> I'd quite like these limit-specifications to be more general. For
> example, I'd quite like to write...
> 
>   if 0 <= x < 10 :
>     print "x is in range"
> 
> There is a big problem with this, of course - this is already legal
> Python, but the semantics aren't what I intend.

exactly.
 
> Looking generally through other PEPs, there seems to be a general
> problem with adding new grammar to the Python language. Some
> contortions are needed to avoid breaking old code.
> I was wondering if maybe it is time that the Python 'core' grammar was
> considered broadly complete, with the exception of a special notation
> specifically designed for the purpose of wrapping new grammar rules.
> 
> I haven't thought through my choice of symbols, but imagine a notation
> such as the following was created...
> 
>   [* indentifier RULE *]

ugh :-) Ugly to read...

>   if [* check 0 <= x < 10 *] :
>     print "OK"

better:

    if 0 <= x and x < 10:
 
>   for [* range 0 <= x < 10 *] :
>     pass

better:    

    for range in xrange(0,10):
	pass

Tell us the truth! You were sent from these evil perl-hackers
on a quest to bring python to perl's line-noise levels :-)

> Obvious Advantages...
> 
> - If the new syntax turns out to be obscure and rarely used, people
>   reading the code that does use it at least have a clear identifier
>   name to look up in the manuals to find an explanation of what it
>   does.

You just made it difficult to read other's code
without looking up some (probably missing:-) documentation.
 
> - With careful choice of delimiters (ie the [* and *] above) this
>   should never cause a code break, and should save a lot of hassle
>   in this respect in the future.

while increasing general hassle.
 
> - Python should be able to give a clear error message if source code
>   intended for a newer version is used (e.g. 'range support not
>   provided in this Python version) by simply picking up the
>   identifier.

I think there is absolutely no chance of something like this ever
beeing integrated.

> - Noticably wordier than necessary, as each new grammar rule has
>   three 'redundant' tokens.
> - Could make it too convenient to add obscure special-purpose
>   features, leading to unnecessary bloat.

exactly.

> Any comments?

kill that perlish devil in you and enjoy python :-)

regards,

     holger





More information about the Python-list mailing list