By listing the code above you've shown why the default must be so,
since calling your function with any of those types will "just
work" (at least before an stack overflow), which of course can't be
done with primitive types. For an untyped language with a worry-free
numeric abstraction, this seems
On Mar 9, 2010, at 1:19 PM, Richard Newman wrote:
>> I suspect that on recursion
>
> If you use plain function-calling recursion, yes. If you use (loop ...
> recur...) then (IIRC) locals are not boxed (as well as saving stack).
>
> Also bear in mind that JIT will come into play here; after a f
I suspect that on recursion
If you use plain function-calling recursion, yes. If you use (loop ...
recur...) then (IIRC) locals are not boxed (as well as saving stack).
Also bear in mind that JIT will come into play here; after a few tens
of thousands of arithmetic ops, the common path wil
On 9 March 2010 15:59, jshore wrote:
[...]
> (defn fib [a]
> (let [v (int a)]
> (if (< v (int 2))
> v
> (+ (fib (- v (int 1))) (fib (- v (int 2)))
>
> I suspect that on recursion a will become an object again and will
> then n
Thanks
The use of (int ...) works, avoiding the dispatch, but it has to be
used everywhere there is a variable or literal. Starts getting very
ugly and unreadable as expressions get longer.Is there any way to
indicate an "int" or "double" literal short of (int 2). Here is the
modified func
Hmm, is there a notation to express an int literal. Better yet,
clojure should try to infer that if I do (+ v 2) where v was hinted to
be "int", 2 should be considered to be an int. The code starts
getting really messy:
(defn fib [a]
(let [v (int a)]
(if (< v (int 2))
On Tue, Mar 9, 2010 at 1:44 AM, Timothy Pratley
wrote:
> On 9 March 2010 04:03, Jonathan Shore wrote:
>> (defn fib [#^Integer a]
>> (if (< a 2)
>> a
>> (+ (fib (- a 1)) (fib (- a 2)
>> I'm just learning, so I may have overlooked something that mitigates or
>> otherwise avoids dispat
On Mar 9, 8:59 am, jshore wrote:
> I suspect that on recursion a will become an object again and will
> then need to be downcasted again as well. Would be nice to be able
> to do:
>
> (defn fib [#^int v]
> (if (< v 2)
> v
> (+ (fib (- v 1)) (fib (- v 2
On 9 March 2010 04:03, Jonathan Shore wrote:
> (defn fib [#^Integer a]
> (if (< a 2)
> a
> (+ (fib (- a 1)) (fib (- a 2)
> I'm just learning, so I may have overlooked something that mitigates or
> otherwise avoids dispatch.
You might want to experiment with something like
(defn fib
Hi,
I was stepping through a very simply test (not meant to be performant) and
noticed the following:
(ns test.performance.fibonachi)
(defn fib [a]
(if (< a 2)
a
(+ (fib (- a 1)) (fib (- a 2)
(fib 45)
Stepping into (if ...) noticed that (< a 2) called into the following Java c
10 matches
Mail list logo