So I was trying this:
user=> (Integer/toBinaryString ^int (.charValue \c))
"1100011"
user=>
And I thought... Well, that looks promising, so let's try this now:
user=> (map #(Integer/toBinaryString ^int (.charValue %)) "some")
ClassCastException java.lang.Character cannot be cast to java.lang.Number user/eval1209/fn--1210 (form-init3852254868488042860.clj:1)
user=> ; Tried this as well. But without luck:
user=> (map #(Integer/toBinaryString ^int (.charValue %)) (.toCharArray "some"))
ClassCastException java.lang.Character cannot be cast to java.lang.Number user/eval1249/fn--1250 (form-init3852254868488042860.clj:1)
user=>
oops! WTF is going on?
I have the thing working after introducing a hack:
user=> (map #(Integer/toBinaryString ^int (.charValue (Character/valueOf %))) "some")
("1110011" "1101111" "1101101" "1100101")
user=> ; Or alternatively:
user=> (map (fn [^Character c] (Integer/toBinaryString ^int (.charValue c))) "some")
("1110011" "1101111" "1101101" "1100101")
user=> ; Or:
user=> (map #(Integer/toBinaryString ^int (.charValue ^Character %)) "some")
("1110011" "1101111" "1101101" "1100101")
user=>
So, does anyone know why this just won't work without calling Character/valueOf or explicitly casting?