Python's "only one way to do it" philosophy isn't good?

Douglas Alan doug at
Thu Jun 28 07:20:49 CEST 2007

Dennis Lee Bieber <wlfraed at> writes:

> 	But if these "macros" are supposed to allow one to sort of extend
> Python syntax, are you really going to code things like
> 	macrolib1.keyword
> everywhere?

No -- I would expect that macros (if done the way that I would like
them to be done) would work something like so:

   from setMacro import macro set, macro let
   let x = 1
   set x += 1

The macros "let" and "set" (like all macro invocations) would have to
be the first tokens on a line.  They would be passed either the
strings "x = 1" and "x += 1", or some tokenized version thereof.
There would be parsing libraries to help them from there.

For macros that need to continue over more than one line, e.g.,
perhaps something like

   let x = 1
       y = 2
       z = 3
   set x = y + z
       y = x + z
       z = x + y
   print x, y, z

the macro would parse up to when the indentation returns to the previous

For macros that need to return values, a new bracketing syntax would
be needed.  Perhaps something like:

   while $(let x = foo()):
      print x


More information about the Python-list mailing list