How to cast a character to int in Clojure?

Posted by Learning Clojure on Stack Overflow See other posts from Stack Overflow or by Learning Clojure
Published on 2013-11-03T03:46:28Z Indexed on 2013/11/03 3:53 UTC
Read the original article Hit count: 174

How to cast a character to int in Clojure?

I am trying to write a rot 13 in clojure, so I need to have something to cast my char to int. I found something called (int), so I put:

(int a)

Get: CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:13:1)

Then I put:

(int 'a)

Get: ClassCastException clojure.lang.Symbol cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087)

Then:

(rot13 ''a')

Get: ClassCastException clojure.lang.PersistentList cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087)

And:

(rot13 "a")

Get: ClassCastException java.lang.String cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087)

So what is the right way to do it?

btw, I always get confused with all these clojure syntax. But I can never find any source only help me with my problem. Any suggestions? Thank you!!

© Stack Overflow or respective owner

Related posts about clojure

Related posts about functional-programming