Hello,
Since maps are functions of their keys, I think you can get away with
something like:

(def unbox {Byte Byte/TYPE
                 Integer Integer/TYPE})

(unbox Integer) ;int

Regarding your let/defn, I think in general if you have functions that
depend on compile-time constants it's idiomatic to def them.

Cheers,
Alan

On May 6, 11:08 am, B Smith-Mannschott <bsmith.o...@gmail.com> wrote:
> On Thu, May 6, 2010 at 15:22, Stuart Halloway <stuart.hallo...@gmail.com> 
> wrote:
> > Reflection is slow, there are less than ten of these, and the possible set
> > ain't gonna change.
>
> > I would write a function that looks them up from a map.
>
> Yea, I considered that too.  The only reason I didn't was because of a
> misguided desire not to hardcode things.
>
> But, you're right. My solution isn't optimal. The set of classes which
> box java primitives is not going to change.
>
> (let [m {Byte      Byte/TYPE,       Short     Short/TYPE,
>          Integer   Integer/TYPE,    Long      Long/TYPE,
>          Boolean   Boolean/TYPE,    Character Character/TYPE,
>          Float     Float/TYPE,      Double    Double/TYPE}]
>   (defn unbox [class]
>     (m class class)))
>
> I've defined 'm' in a let containing the definition of unbox because
> I'm assuming that if I'd inlined it at the point where I use m that it
> would get constructed once for every function call, but I don't
> actually know that:
>
>   (defn unbox [class]
>     ({Byte ...} class class))
>
> Would Clojure be smart enough to recognize that {Byte ...} is a
> compile-time constant expression and not rebuild it on every call to
> unbox?
>
> // Ben
>
> --
> 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 
> athttp://groups.google.com/group/clojure?hl=en

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