bpsm / edn-java

a reader for extensible data notation
Eclipse Public License 1.0
100 stars 24 forks source link

doesn't read clojure ratios #34

Closed martintrojer closed 10 years ago

martintrojer commented 11 years ago
;; clojure defacto-standard edn reader
user=> (clojure.edn/read-string "1/2")
1/2
// scala
val p = newParser(defaultConfiguration())
val r = p.nextValue(newParseable("{:x 1/2}")).asInstanceOf[java.util.Map[Keyword,Any]].toMap

us.bpsm.edn.EdnSyntaxException: Not a number: '1/'.
    at us.bpsm.edn.parser.ScannerImpl.readNumber(ScannerImpl.java:434)
    at us.bpsm.edn.parser.ScannerImpl.scanNextToken(ScannerImpl.java:153)
    at us.bpsm.edn.parser.ScannerImpl.nextToken(ScannerImpl.java:61)
        ...
bpsm commented 11 years ago

Clojure rationals are not valid edn numbers as far as I can tell.

https://github.com/edn-format/edn

edn supports:

Rationals are not mentioned in the spec.

On the other hand, clojure.edn/read accepts rationals without complaint (see EdnReader.java) but that's probably an accident resulting from the fact that EdnReader.java is basically a copy-paste of LispReader.java with some stuff removed.

If edn-java did support reading rational numbers, what type would you expect the result to be? Java doesn't have a standard representation for rational numbers that I'm aware of.

See also edn-format/edn#47.

bpsm commented 10 years ago

Will not implement reading rationals as this is not in the spec.