[Python-Dev] Re: User extendable literal modifiers ?!

M.-A. Lemburg mal@lemburg.com
Fri, 27 Sep 2002 13:17:55 +0200

Gerhard H=E4ring wrote:
> In article <3D9423FB.9070303@lemburg.com>, M.-A. Lemburg wrote:
>>I was wondering whether it would be worth adding something
>>like a registry of literal modifiers to Python,
> Especially for this purpose, that would be great. And have potential fo=
> misuse, too. Just like, say, operator overloading. But in the context o=
> Python, I didn't see any misuse of operator overloading, yet.

I was thinking of giving the current concept of literal
modifiers a more general scope. Of course, this can be
misused, but then we could e.g. put certain constraints
on the possible modifiers, say only allow a predefined
number of modifiers and then have the compiler at
compile time or the interpreter at run-time apply the
necessary logic to the literal to turn it into an

We currently have 'u', 'r', 'U', 'R' as modifiers for strings
(prefixes) and 'l', 'L', 'j', 'J' for numbers (postfix).

>>[...] so that
>>extensions can register new modifiers with the compiler,
>>def create_I_literal(literal_string):
>>     return 'mx.Number.Integer(%s)' % literal_string
>>sys.register_numberlitmod('I', create_I_literal)
> A single literal, however, doesn't (easily) allow you to give precision=
> scale arguments to your decimal literal. That's of course easy if you c=
> declare your variable, which you can't in Python. So we're back to
> constructors/factory functions here, right?

Not really, since mxNumber Integers have arbitrary
precision, so scale and precision are not needed.

Marc-Andre Lemburg
CEO eGenix.com Software GmbH
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/