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))
                        v
                        (+ (fib (- v (int 1))) (fib (- v (int 2)))))))

And still, I believe at the recursive step will be converted into an
Object again and then casted to a value type.   Would be nice to be
able to declare as:

defn fib [#^int a]



On Mar 9, 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 mitigates or
> > otherwise avoids dispatch.
>
> You might want to experiment with something like
> (defn fib [a]
>   (let [ia (int a)]
>     ..........))
>
> I know that seems a little weird but anything passed into or out of a
> function gets boxed to an object type. (int a) coerces to a primitive
> int which for some operations has much better performance.
>
> Regards,
> Tim.

-- 
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

Reply via email to