[Python-Dev] A Hygienic Macro System in Python?
Tim Peters
tim.one@comcast.net
Tue, 19 Mar 2002 20:53:54 -0500
[Guido van Rossum]
> Just throwing out some thoughts.
>
> There are several possible use cases for new customizable syntax:
>
> - resource allocation (lock.acquire(); try-finally: lock.release())
>
> - defining functions with special treatment (e.g. classmethods,
> properties)
>
> - defining class-like things (e.g. Zope-style interface declarations)
With that last I assume (or hope) that you're trying to subsume what Jim
Fulton was trying to get at in the "Context binding" thread on the Zope list
a few weeks back (which was itself a repeat of an earlier proposal nobody
responded to at the time -- wanted to, but couldn't make time).
> Maybe it's possible to invent a new statement that covers all of
> these? Certainly a macro system should support doing all these
> easily...
I'd like to go back to Jim's original statement of "the problem" (since it
was more helpful than the proposed solution <wink>):
It would be cool, IMO, if people could define their own
block statements in Python.
I think all the use cases you had in mind fit this too, and it's not
vacuous. For example, it rules out "expression macros", like trying to
cater to defining
x implies y
as expanding to
((not (x)) or (y))
Python's better off without anything like that; new block statements aren't
nearly as disgusting <wink>.
one-sickly-step-at-a-time-ly y'rs - tim