如何查找Clojure函数(split)的允许选项



Clojure函数spit允许将数据写入文件,例如:

(spit "filename.txt" "content")

它还允许将内容添加到现有文件中。

(spit "filename.txt" "content" :append true)

在文档((doc spit))中,它只表示可以将选项传递给clojure.java.io/writer。但是(doc clojure.java.io/writer)没有列出允许的选项。那么,是否有可用的文档"详细模式"?

我通过找到了:append-选项http://clojuredocs.org/clojure.core/spit,但我相信它也在文档中列出。

可能大多数选项都是从Java底层库映射的

http://docs.oracle.com/javase/tutorial/essential/io/file.html

通过浏览源代码,我确认:encoding是合法的

https://github.com/clojure/clojure/blob/clojure-1.6.0/src/clj/clojure/java/io.clj#L74-L77

Common options include
 :append    true to open stream in append mode
 :encoding  string name of encoding to use, e.g. "UTF-8".

我无法进一步帮助,因为Java不是我更常用的语言,希望它能帮助

通过clojure.java.io/writermake-writer,所以在io.clj中找到了它;

(defprotocol ^{:added "1.2"} IOFactory
  "Factory functions that create ready-to-use, buffered versions of
  the various Java I/O stream types, on top of anything that can
  be unequivocally converted to the requested kind of stream.
  Common options include
   :append    true to open stream in append mode
   :encoding  string name of encoding to use, e.g. "UTF-8".
  Callers should generally prefer the higher level API provided by
  reader, writer, input-stream, and output-stream."
  (^{:added "1.2"} make-reader [x opts] "Creates a BufferedReader. See also IOFactory docs.")
  (^{:added "1.2"} make-writer [x opts] "Creates a BufferedWriter. See also IOFactory docs.")
  (^{:added "1.2"} make-input-stream [x opts] "Creates a BufferedInputStream. See also IOFactory docs.")
  (^{:added "1.2"} make-output-stream [x opts] "Creates a BufferedOutputStream. See also IOFactory docs."))

@爱德华,只有:append:encoding

@Jaime Agudo的答案是对的,我没有看到他的答案:-(.

最新更新