beginners 2026-02-27

(doc slurp) says

-------------------------
clojure.core/slurp
([f & opts])
  Opens a reader on f and reads all its contents, returning a string.
  See  for a complete list of supported arguments.
(doc ) says
-------------------------

([x & opts])
  Attempts to coerce its argument into an open java.io.Reader.
   Default implementations always return a java.io.BufferedReader.

   Default implementations are provided for Reader, BufferedReader,
   InputStream, File, URI, URL, Socket, byte arrays, character arrays,
   and String.

   If argument is a String, it tries to resolve it first as a URI, then
   as a local file name.  URIs with a 'file' protocol are converted to
   local file names.

   Should be used inside with-open to ensure the Reader is properly
   closed.
It's difficult to figure out the options that I can pass to slurp.

(also: Clojure and the Contrib libraries do not accept PRs anyway, only patches attached to Jira tickets, and those tickets are created in response to Ask questions -- see https://clojure.org/dev/dev for more details)

Clojuredocs is also a great resource for this sort of thing (in case you weren't familiar with it) - when I find myself confused by a docstring, chances are that someone has already addressed it there: https://clojuredocs.org/clojure.core/slurp

i run into this kind of stuff often too. read-string says it has the same options as read so i have to consult that. The core async stuff does as well, frequently with full docstrings for the blocking versions and references in the parking versions. Slightly different issue from yours here but in the same spirit i think

➕ 3

Since it's something that could be improved, could you please created a post on https://ask.clojure.org? As for the list of the options: checking (source ) shows that it simply calls make-reader. Calling doc on that show that it asks you to check the docs of IOFactory. And finally checking its docs shows the options.

I am not sure that make-reader actually allows for options

i think they all do essentially this pattern: (fn [x opts] (BufferedReader. x)) where the options are ignored

The source code disagrees with that statement. ;)

can you show where a reader uses options? I certainly see for writers

(extend InputStream
  IOFactory
  (assoc default-streams-impl
    :make-input-stream (fn [x opts] (BufferedInputStream. x))
    :make-reader inputstream->reader))

(defn- inputstream->reader
  [^InputStream is opts]
  (make-reader (InputStreamReader. is (encoding opts)) opts))

(defn- ^String encoding [opts]
  (or (:encoding opts) "UTF-8"))

ah i had missed that one

It seems documentation needs to improve, but I'm not fit to make a pull request because I'm learning clojure.

Yeah, a post on http://ask.clojure.org does not necessitate a PR. It's basically just making the need for improvement much more visible and actionable, plus it adds voting.