tags:

views:

550

answers:

1

How do I convert Symbol to String ,Integer to Float and other similar type conversion in Clojure?

+6  A: 

you tell the compiler what type you want something to be by adding meta-data to it.
this can make some operations faster and help eliminate reflection. The #^ symbol is syntactic sugar for add this to the metadata for whatever comes next.

(defn my-function  [#^String my-string] ....

symbol to string

(str 'my-symbol)

for numbers use the name of the type as a function name

(int 4922354)
(double 42)
(byte 254)
(char 20)
etc...

for more info: http://clojure.org/java_interop#toc35

Arthur Ulfeldt