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
On Tue, Mar 9, 2010 at 1:44 AM, Timothy Pratley
timothyprat...@gmail.com wrote:
On 9 March 2010 04:03, Jonathan Shore jonathan.sh...@gmail.com 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
On Mar 9, 8:59 am, jshore jonathan.sh...@gmail.com 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))
On 9 March 2010 15:59, jshore jonathan.sh...@gmail.com 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
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))
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
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 few
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
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
On 9 March 2010 04:03, Jonathan Shore jonathan.sh...@gmail.com 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
10 matches
Mail list logo