Thoughts on new grammar rules (PEP 284 in particular)

Steve Horne steve at lurking.demon.co.uk
Tue May 14 09:48:03 EDT 2002


On Sat, 11 May 2002 09:52:45 GMT, Alex Martelli <aleax at aleax.it>
wrote:

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

I certainly wasn't suggesting macros. The new facilities would still
need to be accepted and built into the interpreter with my scheme -
and the main bloat filter (objecting Python users) would still be
present.

Actually, though, I rather like macros - just not the way they are
typically handled. Sometimes, code generation can be a better approach
than hand coding. As with any feature, of course, it can be abused -
but that's beside the point. After all, even the unary '-' can be
abused (what is the value of -----------------------------------1 ?)

Ideally, I'd like compiled languages to support this directly - with
the features being invoked at compile (or code generation) time being
as-far-as-possible identical (even in syntax) to those available in
the main code. In fact, I see this as an extreme case of the
optimisation view that if something has no dependency on run-time
data, it should be evaluated at compile-time.

ASP and the like have already approached that problem - providing
'escapes' to say a section of a document is 'calculated' by the server
prior to sending it to the clients browser. I have already written a
code-generation tool which detects some simple escapes while
preprocessing Python source code, so I can use Python (with a few
minor tweaks) to generate C++. It works well enough - but as with any
system of escapes, if overused, it can make a mess.

-- 
Steve Horne
steve at lurking.demon.co.uk



More information about the Python-list mailing list