Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue May 20, 2014 · 6 comments
Open

Comments

@ghost
Copy link

ghost commented May 20, 2014

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
Copy link

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

@ghost
Copy link
Author

ghost commented May 21, 2014

@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 added a commit to swaroopch/edn_format that referenced this issue Jun 23, 2014
@swaroopch
Copy link

@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 - swaroopch/edn_format#23

@rschmitt
Copy link

rschmitt commented Mar 7, 2015

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

bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 16, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 16, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 16, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 16, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 24, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
bfontaine pushed a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
bfontaine added a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
bfontaine added a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
bfontaine added a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
bfontaine added a commit to bfontaine/edn_format that referenced this issue Aug 26, 2018
@SeaJaredCode
Copy link

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
Copy link

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.

gabrielferreira95 added a commit to nubank/edn_format that referenced this issue Nov 25, 2019
* Convert requirements from exact to minimum

Fixes swaroopch#40

* Bump version to 0.5.13

* LICENSE: bump year

* Fix ambiguous variable name (swaroopch#44)

* Add a Changelog

* Fix parsing of exact-precision floats with a negative exposant (swaroopch#47)

* Accept missing printable ASCII chars (swaroopch#45)

* Add a sort_sets optional keyword argument to dump (swaroopch#42)

* add failing unit test

* add ImmutableList

* use ImmutableList on code

* fix latin

* conform to flake8

* add test

* add placeholder file

* workaround for limitation on the image downstream

* remove conda.txt file

* add docstring

* descend from Sequence instead of MutableSequence

* copy explicitly

* remove MutableSequence tests

* bump version

* fix formatting

* use copy.copy()

as .copy() is not available for lists on python2

* remove redundant tests

* simplify condition

* Raise custom exceptions on syntax errors (swaroopch#46)

* Add CONTRIBUTING.md (swaroopch#48)

* Handle fractions

edn-format/edn#64

* Handle #_

Fixes #4.

Note it doesn’t support top-level #_ usage such as in:

    foo #_ bar

* Add tests for #_

* Tweak README regarding caveats + mention @bfontaine contributor

* Bump version to 0.6.0

Thanks @bfontaine and @konr!

* Add v0.6.0 to the Changelog

* Run Travis tests on latest Python 3.7

* Use dist: xenial

* Use mutable data structures to improve parsing time

Previously a list was used to hold the intermediate results during
parsing of "expressions", but each expression was prepended by
copying, Fixing this takes parsing from quadratic to linear time.

* Bump version to 0.6.1

* Update setup.py to 0.6.1

* Various code simplifications (swaroopch#53)

* Parse nil and booleans as symbols (swaroopch#54)

* Add Vagrantfile for local dev

* Use collections.abc instead of collections

Fixes swaroopch#55

* Fix build issues

https://travis-ci.org/swaroopch/edn_format/jobs/475411817

* Fix Python 2.x compatibility

https://travis-ci.org/swaroopch/edn_format/jobs/475413453

* Bump version to 0.6.2

* DRY the requirements

Move from setup.py to only requirements.txt

* Add badge for PyPI version

* add support for unicode char literals

* fixed indentation in test_sort_keys

* combined version_info checks in edn_format/edn_lex.py

Co-Authored-By: LeXofLeviafan <lexofleviafan@gmail.com>

* fixed comment in char token definition

* made changes according to flake8 demands

* Bump version to 0.6.3

* Travis : Upgrade Ubuntu version to latest LTS, bionic

* Use tag signing

* Add an edn_parse.tag decorator, + docs and tests on tags (swaroopch#59)

* Contributor Notes: replace the deprecated commands

* Version 0.6.4

* Move contributor notes in CONTRIBUTING.md (swaroopch#61)

* Add edn_format.loads_all to parse all expressions in a string (swaroopch#60)

* Parse hexadecimal notation

Fixes swaroopch#62.

* Disallow 0-prefixed integers

From the spec:

> No integer other than 0 may begin with 0.

* Release v0.6.5

* Bump version to 0.6.5-nu
gcbeltramini pushed a commit to nubank/edn_format that referenced this issue Nov 27, 2019
* Convert requirements from exact to minimum

Fixes swaroopch#40

* Bump version to 0.5.13

* LICENSE: bump year

* Fix ambiguous variable name (swaroopch#44)

* Add a Changelog

* Fix parsing of exact-precision floats with a negative exposant (swaroopch#47)

* Accept missing printable ASCII chars (swaroopch#45)

* Add a sort_sets optional keyword argument to dump (swaroopch#42)

* add failing unit test

* add ImmutableList

* use ImmutableList on code

* fix latin

* conform to flake8

* add test

* add placeholder file

* workaround for limitation on the image downstream

* remove conda.txt file

* add docstring

* descend from Sequence instead of MutableSequence

* copy explicitly

* remove MutableSequence tests

* bump version

* fix formatting

* use copy.copy()

as .copy() is not available for lists on python2

* remove redundant tests

* simplify condition

* Raise custom exceptions on syntax errors (swaroopch#46)

* Add CONTRIBUTING.md (swaroopch#48)

* Handle fractions

edn-format/edn#64

* Handle #_

Fixes #4.

Note it doesn’t support top-level #_ usage such as in:

    foo #_ bar

* Add tests for #_

* Tweak README regarding caveats + mention @bfontaine contributor

* Bump version to 0.6.0

Thanks @bfontaine and @konr!

* Add v0.6.0 to the Changelog

* Run Travis tests on latest Python 3.7

* Use dist: xenial

* Use mutable data structures to improve parsing time

Previously a list was used to hold the intermediate results during
parsing of "expressions", but each expression was prepended by
copying, Fixing this takes parsing from quadratic to linear time.

* Bump version to 0.6.1

* Update setup.py to 0.6.1

* Various code simplifications (swaroopch#53)

* Parse nil and booleans as symbols (swaroopch#54)

* Add Vagrantfile for local dev

* Use collections.abc instead of collections

Fixes swaroopch#55

* Fix build issues

https://travis-ci.org/swaroopch/edn_format/jobs/475411817

* Fix Python 2.x compatibility

https://travis-ci.org/swaroopch/edn_format/jobs/475413453

* Bump version to 0.6.2

* DRY the requirements

Move from setup.py to only requirements.txt

* Add badge for PyPI version

* add support for unicode char literals

* fixed indentation in test_sort_keys

* combined version_info checks in edn_format/edn_lex.py

Co-Authored-By: LeXofLeviafan <lexofleviafan@gmail.com>

* fixed comment in char token definition

* made changes according to flake8 demands

* Bump version to 0.6.3

* Travis : Upgrade Ubuntu version to latest LTS, bionic

* Use tag signing

* Add an edn_parse.tag decorator, + docs and tests on tags (swaroopch#59)

* Contributor Notes: replace the deprecated commands

* Version 0.6.4

* Move contributor notes in CONTRIBUTING.md (swaroopch#61)

* Add edn_format.loads_all to parse all expressions in a string (swaroopch#60)

* Parse hexadecimal notation

Fixes swaroopch#62.

* Disallow 0-prefixed integers

From the spec:

> No integer other than 0 may begin with 0.

* Release v0.6.5

* Merge with upstream

* Remove repeated tests

* Undo some changes after the merge

* Fix regex for t_FLOAT

* Add more test cases

* Refactor t_FLOAT regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants