Clojure

Read/print round-trip for +/-Infinity and NaN

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test

Description

A few float-related forms (namely, Double/POSITIVE_INFINITY, Double/NEGATIVE_INFINITY, Double/NaN) are not eval-able after a round-trip via

(read-string (binding [*print-dup* true] (pr-str f))

The two options I see are to provide print-method implementations for these and their Float cousins, or to make Infinity, -Infinity, +Infinity, and NaN readable values. Since it sounds like edn may want to provide a spec for these values (see https://groups.google.com/d/topic/clojure-dev/LeJpOhHxESs/discussion and https://github.com/edn-format/edn/issues/2), I think making these values directly readable as already printed is preferable. Something like Double/POSITIVE_INFINITY seems too low-level from edn's perspective, as it would refer to a Java class and constant.

I'm attaching a patch implementing reader support for Infinity, -Infinity, +Infinity, and NaN.

Activity

Hide
Timothy Baldridge added a comment -

Please bring this up on clojure-dev. We'll be able to vet this ticket after that.

Show
Timothy Baldridge added a comment - Please bring this up on clojure-dev. We'll be able to vet this ticket after that.
Hide
Colin Jones added a comment -

Should I respond to my original clojure-dev post about this (linked in the issue description above), or start a new one?

Show
Colin Jones added a comment - Should I respond to my original clojure-dev post about this (linked in the issue description above), or start a new one?
Hide
Andy Fingerhut added a comment -

Patch clj-1074-read-infinity-and-nan-patch-v2.txt dated May 24 2013 is identical to 0001-Read-Infinity-and-NaN.patch dated Sep 21 2012, except it applies cleanly to latest master. The older patch conflicts with a recent commit made for CLJ-873.

Show
Andy Fingerhut added a comment - Patch clj-1074-read-infinity-and-nan-patch-v2.txt dated May 24 2013 is identical to 0001-Read-Infinity-and-NaN.patch dated Sep 21 2012, except it applies cleanly to latest master. The older patch conflicts with a recent commit made for CLJ-873.
Andy Fingerhut made changes -
Field Original Value New Value
Attachment clj-1074-read-infinity-and-nan-patch-v2.txt [ 12006 ]
Hide
Nicola Mometto added a comment -

clj-1074-read-infinity-and-nan-patch-v2-plus-edn-reader.patch is the same as clj-1074-read-infinity-and-nan-patch-v2.txt except it patches EdnReader too, but it must be applied after #CLJ-873 0001-Fix-CLJ-873-for-EdnReader-too.patch get merged

Show
Nicola Mometto added a comment - clj-1074-read-infinity-and-nan-patch-v2-plus-edn-reader.patch is the same as clj-1074-read-infinity-and-nan-patch-v2.txt except it patches EdnReader too, but it must be applied after #CLJ-873 0001-Fix-CLJ-873-for-EdnReader-too.patch get merged
Nicola Mometto made changes -
Andy Fingerhut made changes -
Attachment clj-1074-read-infinity-and-nan-patch-v2.txt [ 12006 ]
Alex Miller made changes -
Labels patch print reader

People

Vote (3)
Watch (1)

Dates

  • Created:
    Updated: