Announcing bytecodehacks 0.10

Michael Hudson mwh21 at cam.ac.uk
Sun May 16 07:25:20 EDT 1999


"Tim Peters" <tim_one at email.msn.com> writes:

> [Michael Hudson]
> > ...
> > I ought to point out I don't really understand macros in scheme
> > (eg. I know there *is* a difference between "hygenic" and
> > "unhygenic" macros, but I don't really get what it is).
> 
> Scheme macros are "structural" as opposed to e.g. C's token-based
> guys, so can't create code wildly different from what the user may
> have expected -- they understand the full rules of the language.
> They also "rename" temp vrbls introduced by the macros so as not to
> shadow those non-local vrbls referenced by the macro expansion.
> IOW, all together, they act a lot like inline functions, with the
> ability to leave argument expressions unevaluated in such a way that
> they *will* evaluate to the same thing after expansion.
> 
> Character- or token-based macros are too stupid to do all that.
> 
> By mucking with things at the bytecode level, you get most of the
> good stuff for free!  A transformation defined at the bytecode level
> is at the right place to avoid confusing surface accidents with
> essential semantics.

Yeah, I was coming round to this conclusion on my own. Eg.  wrt
renaming local variables, I don't have to bother actually renaming the
variables to avoid conflicts, I just use different indices in
(LOAD|STORE)_FAST. This is cool.

It is remarkable that doing this sort of thing at the bytecode level
is far easier that trying it to do it at the source level. I guess it
gets us closer to the scheme-ish 'source code is data' viewpoint. 
Scheme has symbols, Python has bytecodes. Not quite as good, but
considering that this is very very far from the purpose they were
intended for they don't do too badly.

Writing macros is possible now (look at setq.setqize) but it's
fiddly. What we need is another level of abstraction, and I'd like to
do it within what is currently valid Python syntax.

This may or may not be possible.

> hygiene-is-the-first-line-of-defense-against-disease-ly y'rs  - tim

oh-yes-bytecodes-0.12-is-on-starship-if-you're-interested-ly y'rs
Michael




More information about the Python-list mailing list