beginners

doojin 2026-02-27T06:12:40.116319Z

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

seancorfield 2026-02-27T14:45:14.815609Z

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

yuhan 2026-02-28T05:45:28.461849Z

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

dpsutton 2026-02-27T06:15:52.182299Z

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
p-himik 2026-02-27T06:19:26.021959Z

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.

dpsutton 2026-02-27T06:20:02.541449Z

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

dpsutton 2026-02-27T06:20:26.939759Z

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

p-himik 2026-02-27T06:22:09.641819Z

The source code disagrees with that statement. ;)

dpsutton 2026-02-27T06:23:12.895799Z

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

p-himik 2026-02-27T06:23:36.229199Z

(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"))

dpsutton 2026-02-27T06:24:04.893989Z

ah i had missed that one

doojin 2026-02-27T06:36:23.326929Z

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

p-himik 2026-02-27T06:37:14.023509Z

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.

p-himik 2026-02-27T07:21:26.301249Z

I see that you've posted https://ask.clojure.org/index.php/14975/its-difficult-to-figure-out-options-can-pass-slurp-function, thanks!

🙌 5
🙌🏼 1