[Python-Dev] pragmas as callbacks (original) (raw)

Greg Wilson gvwilson@nevex.com
Tue, 29 Aug 2000 10:55:34 -0400 (EDT)


If a mechanism for providing meta-information about code is going to be added to Python, then I would like it to be flexible enough for developers to define/add their own. It's just like allowing developers to extend the type system with new classes, rather than handing them a fixed set of built-in types and saying, "Good luck". (Most commercial Fortran compilers take the second approach, by providing a bunch of inflexible, vendor-specific pragmas. It's a nightmare...)

I think that pragmas are essentially callbacks into the interpreter. When I put:

pragma encoding = "UTF-16"

I am telling the interpreter to execute its 'setEncoding()' method right away.

So, why not present pragmas in that way? I.e., why not expose the Python interpreter as a callable object while the source is being parsed and compiled? I think that:

__python__.setEncoding("UTF-16")

is readable, and can be extended in lots of well-structured ways by exposing exactly as much of the interpreter as is deemed safe. Arguments could be restricted to constants, or built-in operations on constants, to start with, without compromising future extensibility.

Greg