Thank you for the reply.

Does this *(int (or a 0)) *incur any runtime penalty when compared to ^int
(if that would be possible) ? (answer: insignificat)

Well I'll test:
=> *(def a 1)*
#'seesaw.layout/a
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *(int a)* 0))))
"Elapsed time: 7352.883635 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *(int a)* 0))))
"Elapsed time: 7374.908407 msecs"
nil
=> *(def ^Integer a 1)*
#'seesaw.layout/a
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0* a* 0))))
"Elapsed time: 7361.800378 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *a* 0))))
"Elapsed time: 7327.946211 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *a* 0))))
"Elapsed time: 7346.675841 msecs"
nil

;ok again:)
=> *(def a 1)*
#'seesaw.layout/a
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0* (int a)* 0))))
"Elapsed time: 7553.677781 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *(int a)* 0))))
"Elapsed time: 7584.735069 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0* (int a)* 0))))
"Elapsed time: 7500.791362 msecs"
nil
=>* (def ^Integer a 1)*
#'seesaw.layout/a
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0* a* 0))))
"Elapsed time: 7483.519889 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0* a* 0))))
"Elapsed time: 7514.795536 msecs"
nil
=> (time (dorun (doseq [x (take 10000000 (range))]
     (java.awt.Color. 0 0 *a* 0))))
"Elapsed time: 7561.362051 msecs"
nil

So practically no difference, therefore the (int ...) thing is good, thank
you!

Let's see some reflection:

*(def a 1)*
=>* (time (dorun (doseq [x (take 1000000 (range))]
     (java.awt.Color. 0 0 (int (or a 0)) 0))))*
"Elapsed time: 783.968474 msecs"
nil
=> *(time (dorun (doseq [x (take 1000000 (range))]
     (java.awt.Color. 0 0 (int (or a 0)) 0))))*
"Elapsed time: 796.891853 msecs"
nil
=>* (time (dorun (doseq [x (take 1000000 (range))]
     (java.awt.Color. 0 0 (int (or a 0)) 0))))*
"Elapsed time: 778.344676 msecs"
nil
=> *(time (dorun (doseq [x (take 1000000 (range))]
     (java.awt.Color. 0 0 (or a 0) 0))))*
Reflection warning, NO_SOURCE_PATH:2 - call to java.awt.Color ctor can't be
resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to java.awt.Color ctor can't be
resolved.
"Elapsed time: 8195.232631 msecs"
nil
=> *(time (dorun (doseq [x (take 1000000 (range))]
     (java.awt.Color. 0 0 (or a 0) 0))))*
Reflection warning, NO_SOURCE_PATH:2 - call to java.awt.Color ctor can't be
resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to java.awt.Color ctor can't be
resolved.
"Elapsed time: 8557.929886 msecs"
nil

So like +-11 times faster.

the into-array part that you said works but that means I have to *add that
type hint on every call to into-array*, I was hoping maybe that could be
avoided by having into-array do that inside itself, something like
(float-array ...) does, but I guess calling *or *and *into-array *both are
doing the same thing in terms of what they can't do: have their return be
type hinted. I'm not sure if this could ever work since they don't always
return the same type, like *float-array* would do .


On Mon, Feb 18, 2013 at 7:42 PM, Andy Fingerhut <[email protected]>wrote:

> Integer is a "boxed" integer in Java.  It is a full Java Object.  The
> java.awt.Color constructor you are calling takes 4 primitive int
> parameters, not Integer.  Try this:
>
> (set! *warn-on-reflection* true)
> (def a 1)
> (java.awt.Color. (int 0) (int 0) (int (or a 0)) (int 0))
>
>
> I'm not so sure what you are asking for with the into-array part of your
> questions.  The last into-array expression returns a Java array of
> java.awt.Color objects.  If you are trying to pass that to some other Java
> method and you are seeing reflection, and adding a type hint of
> ^"[Ljava.awt.Color;" doesn't work somewhere near there to avoid the
> reflection, it would be good to show a code snippet of what you are trying
> and getting reflection with.
>
> Andy
>
>
> On Feb 18, 2013, at 10:29 AM, AtKaaZ wrote:
>
> For *or*
> => *(set! *warn-on-reflection* true)
>    (def ^Integer a 1)
>    (java.awt.Color. 0 0 ^Integer (or ^Integer a 0) 0)
>    *clojure-version**
> true
> #'cgws.notcore/a
> Reflection warning, NO_SOURCE_PATH:3:1 - call to java.awt.Color ctor can't
> be resolved.
> #<Color java.awt.Color[r=0,g=0,b=1]>
> {:major 1, :minor 5, :incremental 0, :qualifier "*RC16*"}
> => *(java.awt.Color. 0 0 ^Integer (or 0 ^Integer a) 0)*
> Reflection warning, NO_SOURCE_PATH:2:1 - call to java.awt.Color ctor can't
> be resolved.
> #<Color java.awt.Color[r=0,g=0,b=0]>
> =>* (java.awt.Color. 0 0 a 0)*
> #<Color java.awt.Color[r=0,g=0,b=1]>
>
>
> For *into-array*  I don't yet have a sample but what is wanted is this:
> *^{:tag "[Ljava.awt.Color;"} (into-array java.awt.Color (list
> (java.awt.Color. 0 0 0 0)))*
> but what we get is the returned value without the typehint when doing just
> this:
> *(into-array java.awt.Color (list (java.awt.Color. 0 0 0 0)))*
>
>
> I'm not sure which jira issues apply for these, likely this is already
> reported but more generically?
>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to