On Jan 23, 10:48 am, Zak Wilson <zak.wil...@gmail.com> wrote:
> If a speed boost is what you're going for, you can probably get one
> from type coercion and (if you're not worried about overflow)
> unchecked-math. As an example:
>
> (defn step [x0, y0, xn, yn]
>    (let [dx0 (double x0)
>           dy0 (double y0)
>           dxn (double xn)
>           dyn (double yn)
>           xm (unchecked-add (unchecked-subtract (unchecked-multiply xn
> xn)(unchecked-multiply yn yn)) x0)
>           ym (unchecked-add (unchecked-multiply 2 xn yn) y0)]
>       [xm ym]))
>
> It's not pretty, I know, but you could assign shorter names for the
> unchecked-math functions if you end up using them heavily.

There are a couple of separate issues here.

One if the fact that fn args must be objects, thus the type hints
don't help. This 'hinting let' technique is a common way to work
around this.

The bigger issue is that both the call out to step and the recursive
call to try-to-solve go through the Object interface.

The way to handle this is to use a loop with type hints in the top
level of try-to-solve (making that typed loop the target of recur),
and make step a macro, thus both inlining it and leveraging the
preceding hints.

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