print-dup / read+eval identity

83 views
Skip to first unread message

Colin Jones

unread,
Sep 21, 2012, 3:09:32 PM9/21/12
to cloju...@googlegroups.com
Based on the docstring for *print-dup*, I would expect this identity
to hold, for any form f that evaluates cleanly:

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

I'm not sure if that's a reasonable assumption to make, but there are
at least a few cases for f where it doesn't hold:

'(/ 1.0 0) ; prints as "Infinity"
'(/ -1.0 0) ; prints as "-Infinity"
'(/ 0.0 0) ; prints as "NaN"

In REPLy, I'm currently monkey-patching clojure.core/print-method to
print these as "Double/POSITIVE_INFINITY", "Double/NEGATIVE_INFINITY",
"Double/NaN", respectively. I'm doing that due to some implementation
details (which actually may have recently been eliminated), but I'm
curious as to whether that round-trip seems desirable to others.

If so, I'd be happy to provide a patch.

- Colin


--
Colin Jones
@trptcolin

Stuart Sierra

unread,
Sep 21, 2012, 4:51:52 PM9/21/12
to cloju...@googlegroups.com
This is a known problem with the Clojure reader, and edn by extension:
https://github.com/edn-format/edn/issues/2

-S

Colin Jones

unread,
Sep 21, 2012, 8:14:56 PM9/21/12
to cloju...@googlegroups.com
Thanks. Created CLJ-1074 (http://dev.clojure.org/jira/browse/CLJ-1074) with a reader patch instead of print-method extensions.

- Colin
Reply all
Reply to author
Forward
0 new messages