do...until wisdom needed...

Neelakantan Krishnaswami neelk at alum.mit.edu
Thu Apr 19 20:42:41 EDT 2001


On 18 Apr 2001 14:00:50 -0400, Andrew Kuchling <akuchlin at mems-exchange.org>
wrote:
>Paul Prescod <paulp at ActiveState.com> writes:
>> And if some smart people can use hygenic macros to make Python code that
>> is more maintainable or readable, why should they be disallowed? Python
>
> I'm increasingly opposed to new Python features, but I'm still not
> ruling out the idea of hygenic macros.  Their presence might remove
> the pressure to add new features, which would mean the language core
> would be that more stable.

My personal suspicion (and this is just a guess) is that if
syntactically lightweight generators and coroutines were added to
Python, then the pressure for new features would fade.

In Haskell, which is a lazy language in which there is basically zero
pressure for macros, even though the users are all researchers and
academics who can be presumed to be pretty familiar with Lisp. (OCaml
and Scheme, both strict functional language with reasonably big user
communities, both grew macro facilities even though they started
without.)

Now, in an imperative language, coroutines are the way to spell lazy
evaluation. I'm sure Tim Peters can expound on this at length -- he's
the one who taught me this piece of wisdom. So extrapolating from
insufficient data suggests that coroutines will quash the desire for
ever more syntax, since they offer a really simple generalization of
so much of it. (They will kill all desire for new loop syntax dead,
for example.)

> I expect it's very difficult to provide a simple interface for them
> in Python, though, because the syntax, and the resulting parse
> trees, are more complicated and less regular than in Lisp; maybe I'm
> just pessimistic, though.

Having a real AST makes writing correct macros easier rather than
harder, because expanding into a syntactically incorrect form gets
harder. CamlP4 is a good place to look at for ideas in this regard.

Python's real difficulty will be in growing a quasiquote facility --
quasiquote permits the macro rules to look like what they start out as
and what they end up as. Python's indentation rules will make that
harder to spell elegantly. This is IMO a prereq for a usable macro
facility.

All in all, I'd suggest coroutine syntax as the "last feature" for
Python rather than hygienic macros.


Neel



More information about the Python-list mailing list