[Python-Dev] A Hygienic Macro System in Python?
Skip Montanaro
skip@pobox.com
Mon, 18 Mar 2002 16:06:38 -0600
(Tom, you gave up way too easily! Hint for the next time: post to
comp.lang.python instead of the python-dev mailing list. There are at least
20 or 30 people there who will gladly provide positive support for just
about any language change proposal. The lifetime of proposals posted there
thus tends to be correspondingly much longer than those that originate
here. :-)
Tim> OTOH, there are cases like
Tim> lock.acquire()
Tim> try:
Tim> do stuff
Tim> finally:
Tim> lock.release()
Tim> that get really tedious if you need to do them a lot, and
Tim> especially if you need to nest them. Maybe Guido can introduce a
Tim> canned "withlock" macro just for that <ahem>:
Tim> withlock lock:
Tim> do stuff
But, since Tom has given up more or less and Tim has diverted the thread to
his own nefarious uses, I will note that the try/finally lock idiom does get
tedious. Using the same argument as "if Guido wanted 'unless' he'd add it
to the language", I think that if this is important enough, it's important
enough to add to the language. I think a "lock" keyword would be
appropriate:
lock somelock:
do stuff
The biggest problem I found with the try/finally lock idiom was that "do
stuff" can tend to get long, so the vertical distance between lock.acquire()
and lock.release() can be substantial. a lock statement/clause/macro would
remove the need to worry about that visual distance.
Skip