clojure.java.io/pushback-reader

Description

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[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 [2];

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

[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

[2] CLJ-82 and the 2009 message thread

Environment

None

Activity

Show:
David Rupp
January 11, 2015, 5:14 PM

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

import
January 11, 2015, 1:54 PM

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).

David Rupp
January 10, 2015, 10:07 PM

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.

David Rupp
January 10, 2015, 10:05 PM

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

Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Unassigned

Reporter

import

Labels

Approval

Triaged

Patch

Code and Test

Priority

Critical

Affects versions