[Python-ideas] History on proposals for Macros?

Matthew Rocklin mrocklin at gmail.com
Sat Mar 28 17:53:48 CET 2015

Responding to comments off list:

I'm not referring to C-style preprocessor macros, I'm referring to macros
historically found in functional languages and commonly found in many
user-targeted languages built in the last few years.

The goal is to create things that look like functions but have access to
the expression that was passed in.

Some examples where this is useful:

    plot(year, miles / gallon)  # Plot with labels determined by
input-expressions, e.g. miles/gallon

    assertRaises(ZeroDivisionError, 1/0)  # Evaluate the rhs 1/0 within
assertRaises function, not before

    run_concurrently(f(x), f(y), f(z))  # Run f three times in three
threads controlled by run_concurrently

Generally one constructs something that looks like a function but, rather
than receiving a pre-evaluated input, receives a syntax tree along with the
associated context.  This allows that function-like-thing to manipulate the
expression and to control the context in which the evaluation occurs.

There are lots of arguments against this, mostly focused around potential
misuse.  I'm looking for history of such arguments and for a general "Yes,
this is theoretically possible" or "Not a chance in hell" from the
community.  Both are fine.


On Fri, Mar 27, 2015 at 4:24 PM, Luciano Ramalho <luciano at ramalho.org>

> On Fri, Mar 27, 2015 at 8:19 PM, Matthew Rocklin <mrocklin at gmail.com>
> wrote:
> > I want Python to have macros.  This is obviously a hard sell.  I'm
> willing
> > to do some legwork to demonstrate value.
> You're probably aware of this "prior art", but anyway, it's worth a
> link. Looks solid to me:
> https://github.com/lihaoyi/macropy
> Cheers,
> Luciano
> --
> Luciano Ramalho
> |  Author of Fluent Python (O'Reilly, 2015)
> |     http://shop.oreilly.com/product/0636920032519.do
> |  Professor em: http://python.pro.br
> |  Twitter: @ramalhoorg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150328/ac9905cf/attachment.html>

More information about the Python-ideas mailing list