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

Paul Prescod paul@prescod.net
Mon, 18 Mar 2002 13:41:50 -0800


Tom Emerson wrote:
> 
>...
> Sure, here's one from Dylan, that provides a useful bit of syntactic
> sugar that makes some code easier to read:
> 
>   define macro unless
>     { unless (?test:expression) ?:body end }
>      => { if (~ ?test) ?body end }

I think that's a poor example. If Guido wanted to read Python code with
unless in it he would just add it to the language. If you want to make a
case for macros then I would suggest you use an example some obscure
domain where Guido doesn't know enough to recognize that Python is
already good enough as it is. ;) Niel S is on the right track describing
workarounds he's had to do for "eval" and import hooks. In that case the
need was severe enough that they decided to make a Python-like language
even though it was quite difficult. So they've proven that they needed
something like macros enough to implement something like them
themselves. Macros' cost in compile-time is high enough that IMO you
should only use them when you really need them. And I would want them to
be very glaring...as in:

macro unless(has_foo(bar)):
   do_something()

I want to really be clear when I read code of what's built-in and what's
extension stuff.

 Paul Prescod