[Python-ideas] History on proposals for Macros?

Guido van Rossum guido at python.org
Mon Mar 30 02:53:43 CEST 2015


On Sat, Mar 28, 2015 at 9:53 AM, Matthew Rocklin <mrocklin at gmail.com> wrote:

> 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.
>

Do you have examples and references? IIRC there's something named macros in
Scheme but Scheme, unlike Python, completely unifies code and data, and
there is a standard in-memory representation for code.


> 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.
>

None of the examples need the syntax tree though. The first wants the
string, the last probably just want a way to turn an argument into a lambda.


> 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.
>

I don't think this is a mainline need in Python, so it's probably both. :-)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150329/ee412506/attachment.html>


More information about the Python-ideas mailing list