[Python-Dev] A Hygienic Macro System in Python?

Tim Peters tim.one@comcast.net
Mon, 18 Mar 2002 16:49:37 -0500


[Jeremy Hylton]
> Funny you should pick this example!  I have been struggling
> with a collection of C code where the author used an
> UNLESS() macro.  I find it obscures the program logic
> significantly.

Python's own cPickle.c uses an UNLESS macro 135 times.  That doesn't mean it
doesn't also use "if (! ...)", and indeed there's no predicting when it may
get used.  It makes cPickle.c hard to work with too.

Python gets a lot of mileage out of reducing the number of "preference ways"
to spell things:  you spell a thing the way Guido likes to spell it, and
everyone's happy <wink>.

OTOH, there are cases like

    lock.acquire()
    try:
        do stuff
    finally:
        lock.release()

that get really tedious if you need to do them a lot, and especially if you
need to nest them.  Maybe Guido can introduce a canned "withlock" macro just
for that <ahem>:

    withlock lock:
        do stuff