Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Syntax and reader by
retagged by

A friend of mine is writing a DSL and wants to use the character ૪ as part of his notation. If you try to use this character as part of a symbol in clojure you get an error like the following:

user=> (read-string "૪")
Execution error (NumberFormatException) at user/eval5 (REPL:1).
Invalid number: ૪

The cause of this appears to be:

user=> (Character/isDigit \૪)

The character is a digit in Gujarati script so java's Character/isDigit returns true, so the clojure reader tries to parse it as a number, but it can only handle arabic numerals (and maybe hex).

It seems like if the reader is going to rely on Character/isDigit, it should be able to turn any of those characters into a number or the reader should allow "digits" it doesn't know how to handle to be symbols.

2 Answers

0 votes

In general, Clojure's intent here is to mostly be "like Java" so would be useful to see how Java treats \૪.

I believe Java parsing would not treat this as a number and thus probably Clojure also should not.
I was a bit surprised by this but:

dev=> (Long/parseLong "૪")


dev=> (Long/parseLong "૪૪૪")

I'm talking about numeric literals in Java code, which will not parse (JLS requires ascii digits 0-9).
0 votes