Clojure

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

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.4
  • Fix Version/s: Release 1.9
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

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 ##Inf, ##-Inf, ##+Inf, and ##NaN.

Patch: clj-1074-8.patch

  1. 0001-CLJ-1074-add-Inf-Inf-Inf-NaN.patch
    06/Sep/17 9:42 AM
    5 kB
    Nicola Mometto
  2. 0001-CLJ-1074-add-Inf-Inf-Inf-NaN-v2.patch
    06/Sep/17 1:55 PM
    4 kB
    Nicola Mometto
  3. 0001-Read-Infinity-and-NaN.patch
    21/Sep/12 7:13 PM
    2 kB
    Colin Jones
  4. clj-1074-2.patch
    24/Oct/16 9:43 AM
    3 kB
    Alex Miller
  5. clj-1074-3.patch
    30/Jun/17 9:03 AM
    3 kB
    Alex Miller
  6. clj-1074-5.patch
    07/Sep/17 8:20 AM
    8 kB
    Alex Miller
  7. clj-1074-6.patch
    07/Sep/17 11:47 AM
    8 kB
    Alex Miller
  8. clj-1074-7.patch
    07/Sep/17 1:31 PM
    9 kB
    Alex Miller
  9. clj-1074-8.patch
    07/Sep/17 1:44 PM
    9 kB
    Alex Miller
  10. clj-1074-read-infinity-and-nan-patch-v2-plus-edn-reader.patch
    25/May/13 11:55 AM
    2 kB
    Nicola Mometto

Activity

People

Vote (7)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: