Alternate numeric proposal

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Mon Jul 23 09:04:39 EDT 2001


----- Original Message -----
From: "Erik Max Francis" <max at alcyone.com>


> Chris Gonnerman wrote:
> >
> > I have been following (and participating) in the integer division
> > argument for some time (and a divisive one it is, too), and while
> > standing in the shower (really!) an idea came to me.
> >
> > Why don't we add a hook to Python to control the numeric evaluation
> > rules directly?
> ...
> > The module writer says, HEY, what about me?  I need consistent math
> > in my module!
>
> That's exactly the problem here.  One of the primary reasons people are
> objecting to the change is because it means a fundamental change in the
> core language:  a builtin operator behaves differently.  The solution is
> not generalizing all builtin operators, certainly -- that makes the
> problem infinitely worse.

Read a bit further down my rambling post and you'll see that I suggest
allowing modules to declare their own default math rules.

The semantics I was trying to figure out at 12:05 AM local time this
morning are clearer in the daylight:

    Lookup operators in module scope,
    Fall back to global (__builtins__) scope, then
    Default to (some standard) operators package

I was hoping that it could be arranged so that the main program/module
could call

    import tutorial_math

and have it installed immediately in the global scope, but then calling

    import advanced_math

in a module would have to *not* screw with the global scope.

Now I think that the main program should do this:

    import tutorial_math
    __builtins__.numerics = tutorial_math.numerics

where the .install() function would rewrite the global setting.  A module
would do this:

    import rational_math
    __numerics__ = rational_math.numerics

Going through the entire standard library and inserting the *same two lines*
a the top of all the pure Python modules wouldn't be hard at all.

Having offered this, I'm not sure I like it... but I do like the idea of
programmers of all stripes (novice to advanced) being able to specify how
basic arithmetic should work.  Novices would (we hope) use only math modules
created by experts, but this gives the experts powerful tools.

Also, it's explicit rather than implicit.






More information about the Python-list mailing list