Thoughts on new grammar rules (PEP 284 in particular)

Alex Martelli aleax at aleax.it
Sat May 11 05:52:45 EDT 2002


Steve Horne wrote:
        ...
> 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.

As many have pointed out, this is probably not true.

> I haven't thought through my choice of symbols, but imagine a notation
> such as the following was created...
> 
>   [* indentifier RULE *]

One stray thought I had at IPC10 after listening to some of Tim
Berners-Lee's wildest syntax suggestion was to allow some "compile
time function call" notation such as...:

identifier(:whatever:)

This would basically be the same as:

identifier('''whatever''')

except that the compiler would notice the (: ... :) form and perform
the call *during compilation* -- the function would probably have
to be defined with a similar "compile-time function definition":

def identifier(:formalarg:):
        ...

notation, and would return any object suitable as first argument
to builtin function 'compile' (codeobject, string) so code generation
could proceed.

Guido started quizzing me when I mentioned it and it rapidly
emerged that I hadn't thought it through -- as indeed I hadn't,
it WAS just a stray thought.  He even mentioned that this could be
seen as a 'macro', thereby causing me to recoil in horror (I've
seen what macros do to languages and don't like it one bit:-).

> - Noticably wordier than necessary, as each new grammar rule has
>   three 'redundant' tokens.

Nah...:

loop_with(: 1 <= x <= 10 :) :
    print x

has fewer tokens than today's "for x in range(1, 11):" equivalent.
That's definitely not the problem.


> - Could make it too convenient to add obscure special-purpose
>   features, leading to unnecessary bloat.

Ay, there's the rub.  Multiple mutually incompatible bloatings
as each group of clever people rushes off to invent their own
clever sets of macros (<horror> <recoil/> </horror>).


Alex




More information about the Python-list mailing list