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:
- What am I doing wrong here?
- How do I get the ordinal/int/ascii value of a character in clojurescript?
kongeor
Clojurescript does not have character literals.
As described here you can get it using js interop:
=> (.charCodeAt \a 0)
97
来源:https://stackoverflow.com/questions/37775349/ordinal-int-ascii-value-of-character