Open ghost opened 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?
@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?
@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
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
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.
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.
It seems that the ratio datatype is simply missing from the specification. Nevertheless
pr-str
andclojure-edn/read-string
both handle ratios ,e.g.1/2
3/5
, as if they were part of the spec.