Welcome! Please see the About page for a little more info on how this works.

0 votes
in Syntax and reader by

Whereas
- clojure.core/read and clojure.edn/read require a PushbackReader;
- clojure.java.io/reader produces a BufferedReader, which isn't compatible;
- the hazard has tripped folks up for years(link: 1);
- clojure.java.io is pure sugar anyway (and would not be damaged by the addition of a little bit more);
- clojure.java.io's very existence suggests suitability and fitness for use (wherein by the absence of a read-compatible pushback-reader it falls short);

i.e., in the total absence of clojure.java.io it would not seem "hard" to use clojure.edn, but in the presence of clojure.java.io and its "reader" function, amidst so much else in the API that does fit together, one keeps thinking one is doing it wrong;

and
- revising the "read" functions to make their own Pushback was considered but rejected (link: 2);

Therefore let it be suggested to add clojure.java.io/pushback-reader, returning something consumable by clojure.core/read and clojure.edn/read.

(link: 1) The matter was discussed on Google Groups:

(2014, "clojure.edn won't accept clojure.java.io/reader?") https://groups.google.com/forum/#!topic/clojure/3HSoA12v5nc

with a reference to an earlier thread

(2009, "Reading... from a reader") https://groups.google.com/forum/#!topic/clojure/_tuypjr2M_A

(link: 2) CLJ-82 and the 2009 message thread

5 Answers

0 votes
by

Comment made by: davidrupp

Attached patch drupp-clj-1611.patch implements clojure.java.io/pushback-reader as requested.

0 votes
by

Comment made by: davidrupp

Note that you can always import java.io.PushbackReader and do something like (PushbackReader. (reader my-thing)) yourself; that's really all the patch does.

0 votes
by

Comment made by: pbwolf

clojure.java.io/reader is idempotent, while the patch of 10-Jan-2015 re-wraps an existing PushbackReader twice: first with a new BufferedReader, then with a new PushbackReader.

Leaving a given PushbackReader alone would be more in keeping with the pattern of clojure.java.io.

It also needs a docstring. If pushback-reader were idempotent, the docstring's opening phrase could echo clojure.java.io/reader's, e.g.: Attempts to coerce its argument to java.io.PushbackReader; failing that, (bla bla bla).

0 votes
by

Comment made by: davidrupp

Adding drupp-clj-1611-2.patch to address previous comments.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1611 (reported by alex+import)
...