edn-format / edn

Extensible Data Notation
2.62k stars 96 forks source link

Ratio datatype is not part of the spec even though clojure.edn supports it. #64

Open ghost opened 10 years ago

ghost commented 10 years ago

It seems that the ratio datatype is simply missing from the specification. Nevertheless pr-str and clojure-edn/read-string both handle ratios ,e.g.1/2 3/5, as if they were part of the spec.

user=> (pr-str 2/4)
"1/2"
user=> (clojure.edn/read-string "1/2")
1/2
swaroopch commented 10 years ago

@ticking Since there is no built-in ratio type in Python, any suggestions on what would be the ideal way to handle this?

ghost commented 10 years ago

@swaroopch To me it seems that there is a module in the python std lib since 2.6 called fractions which introduces a ratio type.

EDIT: Nevertheless the problem of a target language not supporting different EDN types seems to be a reasonable concern. So the question is, how is this handled for other datatypes (e.g. symbols and keywords)? edn_python seems to go with custom classes for keywords and symbols. Would this be appropriate for ratios as well or should it fall back and turn the ratio into a simple float?

swaroopch commented 10 years ago

@ticking Sorry for my confusion, I thought this was a issue raised on my own edn_format Python library, I didn't realize before that this issue was raised on the EDN spec. But to follow up, I have implemented the same for my library - https://github.com/swaroopch/edn_format/pull/23

rschmitt commented 9 years ago

It doesn't look like the Ratio type is supported by edn-ruby either:

~ # irb
2.2.0 :001 > require 'edn'
 => true
2.2.0 :002 > EDN.read("24")
 => 24
2.2.0 :003 > EDN.read('"asdf"')
 => "asdf"
2.2.0 :004 > EDN.read('3/25')
 => 3
SeaJaredCode commented 5 years ago

I think the main point is being missed here. Is EDN supposed to support ratios? If so, the spec needs to include it. If not, then why have a de facto reference implementation support extensions out of spec? (This being one among several exceptions.)

There's a separate issue on what to do for host languages, but can anyone address the spec issue? Actually, any sign of life on this spec would be nice to see. It appears to be 4 years since a spec question was posed and answered by anyone.

edporras commented 5 years ago

It doesn't look like the Ratio type is supported by edn-ruby either:

~ # irb
2.2.0 :001 > require 'edn'
 => true
2.2.0 :002 > EDN.read("24")
 => 24
2.2.0 :003 > EDN.read('"asdf"')
 => "asdf"
2.2.0 :004 > EDN.read('3/25')
 => 3

Hi, just stumbled upon this while thinking about this in regards to edn-ruby.

I'm the developer of edn_turbo, a gem that implements a Ragel-based C-parser plugin replacement for edn-ruby's native one. Although edn-ruby does not support Ratio literals, I've implemented support in edn_turbo using ruby Rationals. Released in v0.6.1 of the gem, available via rubygems.