This imposes too high a burden on any programmer who cares about
safety.
Don't buy it. That's the whole point of BigInt contagion. If fact
and foo are correctly written this will work.
It only takes one library to screw up, and the whole stack falls down.
Screwing up can occur because of omission (fact being written with a
"1", not "1N", and not being tested with large inputs), or by design.
This whole debate arose because people care about the speed of their
numeric functions! The safety bignums (which make things slower) will
be omitted for performance reasons, or by accident, and people won't
obey the contract of the function… or won't be able to because of the
complex interactions between libraries. I can't control where every
value in my program goes.
In Clojure as it stands now, those edge cases would see a small
performance penalty as bignums occurred (and then it would go away if
they got demoted!). After this change, a one-in-a-million collision of
numbers and performance-oriented programming would throw an exception
with no way to recover from higher up the stack.
A programmer who really cares about safety would thus indeed have to
shoulder a massive burden: either review and get complete test
coverage over every library in their dependency stack, or ensure that
no non-bignum can ever enter a library function. I guess that also
means no strings, no file sizes, no URLs, no values which might get
recombined… because any of those values could produce a non-bignum and
enter an unsafe Clojure library function, causing an overflow with no
possibility of continuing. (This ain't Common Lisp.)
Having digested Rich's notes, pretty much the only thing that I
disagree with is the lack of automatic bignum promotion/demotion. It
seems like too much of a bad tradeoff, sacrificing one of Clojure's
selling points for a little numeric performance. Thus far, Clojure has
done pretty well in lexically scoping its "please make this fast and
unsafe" bits — primitive calls, loop, transients. This would break
that pattern.
I wonder: is there's a middle ground, where primitives are automatic
almost everywhere, but bignum promotion on overflow is still possible?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en