[Python-ideas] Retain string form of AST Numbers
Ryan Gonzalez
rymg19 at gmail.com
Sat Apr 5 22:42:58 CEST 2014
On Sat, Apr 5, 2014 at 9:03 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sun, Apr 6, 2014 at 12:32 AM, Ryan <rymg19 at gmail.com> wrote:
> > I could probably try that if you give a slightly clearer description.
>
> Currently, you can fire up IDLE or interactive Python and use it as a
> super calculator:
>
> >>> 1 + 2
> 3
>
> And when you use it with non-integers, you get floats:
>
> >>> 0.1 + 0.2
> 0.30000000000000004
>
> We could turn this into a Decimal calculator with two important changes:
> 1) Every instance of a number in the code must become a Decimal (which
> really means wrapping every number with Decimal("...") and importing
> Decimal from decimal)
>
Simple enough.
> 2) Monkey-patch Decimal.__repr__ = Decimal.__str__ to make the display tidy
>
I actually found a module to do that:
https://pypi.python.org/pypi/forbiddenfruit/0.1.1. Dangerous but awesome.
> The latter might be better done by subclassing Decimal and putting
> something into the builtins, but that's implementation detail (now
> that Decimal is implemented in C, its attributes can't be set).
>
> As long as you don't need multiple contexts or anything complicated
> like that, this should in theory work. (Changing the default context
> shouldn't break anything AFAICT.) It'd then be usable in the same way
> that REXXTry is: a convenient calculator that's backed by a full
> programming language. It'd be better than REXXTry, in fact, as
> limitations on REXX's 'INTERPRET' command mean you can't define
> functions that way (though you can call functions defined in REXXTry
> itself - I had my own Enhanced REXXTry with gobs of mathematical
> utility functions).
>
> If that can be done without any core language changes, that would be
> awesome.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140405/2e0f296f/attachment.html>
More information about the Python-ideas
mailing list