Just tried out num branch and I really like how easy it is to be fast! However...
Consider: (defn fact [n] (if (zero? n) 1 (* n (fact (dec n))))) (defn twice-fact [n] (fact (fact n))) (defn bad-twice-fact [n] (fact (-> n fact range last inc))) user=> (fact (fact 5)) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:3) user=> (fact (fact 5N)) 6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000N user=> (twice-fact 5) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:5) user=> (twice-fact 5N) 6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000N user=> (bad-twice-fact 5) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:7) user=> (bad-twice-fact 5N) java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:8) > Don't buy it. That's the whole point of BigInt contagion. If fact and foo > are correctly written this will work. BigInt contagion doesn't help if in some convoluted manner a BigInt's value is used to construct a primitive sufficiently large that later causes an overflow. It'd sure be nice if I could just write ((safe bad-twice-fact) 5) and get back a BigInt. Maybe ((safe foo) x) can ensure all arguments and return values of function foo are boxed, and recursively, ensures boxing of arguments and return values for all functions called by foo, etc. Is that possible? Would that guarantee safety? Carson On Jun 17, 11:35 pm, David Nolen <dnolen.li...@gmail.com> wrote: > On Fri, Jun 18, 2010 at 2:10 AM, Mark Engelberg > <mark.engelb...@gmail.com>wrote: > > > Elaborating on Anthony's explanation, let's say you call (fact (foo n)). > > 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. > > > > (defn fact [n] > (if (zero? n) 1N (* n (fact (dec n))))) > > (defn foo [n] > (inc n)) > > (fact (foo 40)) > (fact (foo 40N)) > > Both work. -- 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