[Python-Dev] defmacro (was: Anonymous blocks)

Michael Walter michael.walter at gmail.com
Tue Apr 26 05:15:52 CEST 2005

A couple of examples out of my tired head (solely from a user perspective) :-)

Embedding domain specific language (ex.: state machine):

stateful Person:
  state Calm(initial=True):
    def react(event):

  state Furious:
    def react(event):
      self.say("Macros are the evil :)")
      react(event) # xD

p = Person()


Embedding domain specific language (ex.: markup language):

# no, i haven't thought about whether the presented syntax as such is
# enough to make sense
def hello_world():
      <title>: "Tralalalala"
      for g in uiods:
        <h1>: uido2str(g)


Embedding domain-specific language (ex.: badly-designed database table):

deftable Player:
  id: primary_key(integer) # does this feel backward?
  handle: string
  fans: m2n_assoc(Fan)


Control constructs:

  print "tralalala"

unless you.are(LUCKY):
  print "awwww"

I'm not sure whether this the Python you want it to become, so in a
certain sense I feel kind of counterproductive now (sublanguage design
is hard at 11 PM, which might actually prove someone's point that the
language designer shouldn't allow people to do such things. I'm sure
other people are more mature or at least less tired than me, though,
so I beg to differ :-),

On 4/25/05, Guido van Rossum <gvanrossum at gmail.com> wrote:
> It seems that what you call macros is really an unlimited
> preprocessor. I'm even less interested in that topic than in macros,
> and I haven't seen anything here to change my mind.
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/michael.walter%40gmail.com

More information about the Python-Dev mailing list