[Python-Dev] defmacro (was: Anonymous blocks)
Guido van Rossum
gvanrossum at gmail.com
Mon Apr 25 18:52:03 CEST 2005
> I've been following this conversation, and it sounds to me as if we
> are stumbling about in the dark, trying to feel our way toward something
> very useful and powerful. I think Jim is right, what we're feeling our
> way toward is macros.
> The problem, of course, is that Guido (and others!) are on record as
> being opposed to adding macros to Python. (Even "good" macros... think
> lisp, not cpp.) I am not quite sure that I am convinced by the argument,
> but let me see if I can present it:
> Allowing macros in Python would enable individual programmers or
> groups to easily invent their own "syntax". Eventually, there would
> develop a large number of different Python "dialects" (as some
> claim has happened in the Lisp community) each dependent on macros
> the others lack. The most important casualty would be Python's
> great *readability*.
> (If this is a strawman argument, i.e. if you know of a better reason
> for keeping macros OUT of Python please speak up. Like I said, I've
> never been completely convinced of it myself.)
Nor am I; though I am also not completely unconvinced! The argument as
presented here is probably to generic; taken literally, it would argue
against having functions and classes as well...
My problem with macros is actually more practical: Python's compiler
is too dumb. I am assuming that we want to be able to import macros
from other modules, and I am assuming that macros are expanded by the
compiler, not at run time; but the compiler doesn't follow imports
(that happens at run time) so there's no mechanism to tell the
compiler about the new syntax. And macros that don't introduce new
syntax don't seem very interesting (compared to what we can do
> I think it would be useful if we approached it like this: either what
> we want is the full power of macros (in which case the syntax we choose
> should be guided by that choice), or we want LESS than the full power
> of macros. If we want less, then HOW less?
> In other words, rather than hearing what we'd like to be able to DO
> with blocks, I'd like to hear what we want to PROHIBIT DOING with
> blocks. I think this might be a fruitful way of thinking about the
> problem which might make it easier to evaluate syntax suggestions. And
> if the answer is that we want to prohibit nothing, then the right
> solution is macros.
I'm personally at a loss understanding your question here. Perhaps you
could try answering it for yourself?
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev