On Jan 22, 6:16 pm, Korny Sietsma <ko...@sietsma.com> wrote:
> Hi folks,
> Is there any way to make a function that takes primitive parameters?
> It seems you can't, but I might be missing something.
> I have the following code (a start to playing with mandelbrot sets):
>
> (defn step [x0, y0, xn, yn]
> (let [xm (+(-(* xn xn)(* yn yn)) x0)
> ym (+(* 2 xn yn) y0)
> ]
> [xm ym]
> )
> )
>
> (defn try_to_solve [x0, y0, xn, yn, n, max_n]
> (let [m (+ n 1)
> [xm ym] (step x0 y0 xn yn)
> zm (+(* xm xm)(* ym ym))
> ]
> (cond
> (> zm 2.0) m
> (>= n max_n) [x0, y0, xm, ym, m, max_n]
> true (recur x0, y0, xm, ym, m, max_n)
> )
> )
> )
>
> This works fine (it's my first clojure code, so I'm sure there are
> things I could do better, but I'm happy with it as a start)
> However, I want to do this a lot, so I was trying to coerce the
> paramters to primitive doubles.
> It seems you can't write:
> (defn step [#^double x0, #^double y0, #^double xn, #^double yn]
> and from comments I've seen before, I get the impression if I use type
> hinting, clojure will use Doubles and boxing, which is a speed
> overhead I don't want.
>
> I get the impression I can rewrite "try_to_solve" to use a loop/recur,
> and then can use primitives - but I can't see any way to make calls to
> "step" use primitives, short of inlining the function...
>
Currently, there is no way to write a function that takes/returns
primitives, all of the signatures are Object based.
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
-~----------~----~----~----~------~----~------~--~---