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 <> wrote:
On Fri, Mar 27, 2015 at 8:19 PM, Matthew Rocklin <> 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:



Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|  Professor em:
|  Twitter: @ramalhoorg