A = X > Y ? X : Y

Evan Simpson evan at 4-am.com
Thu Feb 10 09:46:22 EST 2000


Michael Hudson <mwh21 at cam.ac.uk> wrote in message
news:m33dr1wj40.fsf at atrus.jesus.cam.ac.uk...
> > Sure it does.  They're called bytecodehacks :-)
>
> Thanks for the plug.

I was hoping to thank you in person at IPC8; byecodehacks has been very good
to me :-)

> > Even better, they are
> > *semantic* macros
>
> Evan, what are you talking about here?

I may be abusing terminology horribly here, but my point was that I can get
effects from bch that I can't imagine getting from mere cpp
text-substitution stuff.  For instance, my PythonMethods Zope product uses
bch to make a function definition "safe".  It ensures that no reference is
made to variables beginning with '_', that no assignment or deletion of
elements/attributes/slices takes place, and that nothing is imported or
exec'd.  I don't make any of these effects dependent on the presence of a
bch 'macro' name, but I *could*.

Another example I've thought about implementing is a 'loopexit' macro, which
would be used thusly:

try:
  for x in xxx:
    while x:
      #stuff
      if stitch in time:
        raise 'Found Stitch'
      #more stuff
except loopexit('Found Stitch'):
  print 'Found it!'

...transforming the 'raise' into a simple jump as in my proposed 'try:
continue:' syntax.

Try that with normal macros!  The only two limitations I find on bch are the
need to explicitly process functions, and the fact that the unprocessed code
must be syntactically correct normal Python; No wholesale redefinition of
syntax :-)

Cheers,

Evan @ digicool





More information about the Python-list mailing list