[Python-Dev] A Hygienic Macro System in Python?

Samuele Pedroni pedroni@inf.ethz.ch
Wed, 20 Mar 2002 03:01:46 +0100


From: Guido van Rossum <guido@python.org>
> Just throwing out some thoughts.
> 
> There are several possible use cases for new customizable syntax:
> 
> - resource allocation (lock.acquire(); try-finally: lock.release())
> 
> - defining functions with special treatment (e.g. classmethods, properties)
> 
> - defining class-like things (e.g. Zope-style interface declarations)
> 
> Maybe it's possible to invent a new statement that covers all of
> these?  Certainly a macro system should support doing all these
> easily...

Mad mad idea, parametric syntax instead of extensible

try:
  this()
finally
  that()

can be rewritten has:

try[finally=that]: # or some other brackets, maybe with also a pre
  this

or

try[this,finally=that]

Ok that's thin-ice, but

class[f] C(A,B) # maybe not using class?
   suite

equivalent to:

C=f((A,B),dictionary-from-execution-of-suite)

and so def[f,g] ...

etc <wink>.
  
Hopefully we don't have even just internally smalltalk-like
anonymous blocks otherwise I would have had more wild
ideas about cflow-statement-like constructs that maps to
function invocations [*].

All of this is maybe ugly, but has the nice property that
things happen only at runtime, also for what I had
in mind for [*].

regards.