[Python-ideas] Python Numbers as Human Concept Decimal System
David Mertz
mertz at gnosis.cx
Tue Mar 11 17:11:16 CET 2014
I think that the dynamic scoping of getcontext() *is* a problem, but
lexical scoping wouldn't actually solve the issue at hand with decimal
literals. Even if we imagined a lexically scoped future with local
causality, this code would still produce unpredictable results and would
not allow constant folding:
def add_contst(d):
decimal.lexical_getcontext().prec(random.randint(1,28))
return d + 1234.567890d
I'm strongly in favor of Oscar's approach of making a decimal literal be
fixed precision (e.g. decimal128; I prefer that to decimal64). More
advanced users are welcome to cast that literal to decimal.Decimal with a
particular context, but basic users will find this the least surprising
approach.
On Tue, Mar 11, 2014 at 8:45 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Le 11/03/2014 16:26, Paul Moore a écrit :
>
>
>> It feels to me as if what we're discovering here is why dynamic
>> scoping is a bad thing. If context was lexically scoped, all of this
>> concern about "action at a distance" and user code impacting library
>> behaviour would go away.
>>
>
> I don't think that's the problem. What you call "dynamic scoping" is a
> feature here, and "lexical scoping" wouldn't solve the issue: simply, the
> parser and compiler run before executing any Python code, so they can't see
> any changes in decimal precision triggered by a library call.
>
> Regards
>
> Antoine.
>
>
>
> _______________________________________________
> 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/
>
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140311/c318ae20/attachment.html>
More information about the Python-ideas
mailing list