user12341234
user12341234

Reputation: 7223

Ordinal/int/ascii value of character

In the clojure repl I can do:

=> (int \a)
97

In closurescript, I keep getting

=> (int \a)
0

In my current clojurescript project I've defined a var:

(def ord-a (int \a))

When I inspect the emitted javascript I see:

ord_a = ("a" | (0));

Which explains the discrepancy, but doesn't really do what I want. So:

  1. What am I doing wrong here?
  2. How do I get the ordinal/int/ascii value of a character in clojurescript?

Upvotes: 5

Views: 784

Answers (1)

kongeor
kongeor

Reputation: 732

Clojurescript does not have character literals.

As described here you can get it using js interop:

=> (.charCodeAt \a 0)
97

Upvotes: 10

Related Questions