如何找出Clojure函数(吐)的允许选项?

时间:2014-10-21 10:28:37

标签: java clojure documentation

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

(spit "filename.txt" "content")

它还允许向现有文件添加内容。

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

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

我通过http://clojuredocs.org/clojure.core/spit找到了:append - 选项,但我确定它也列在文档中的某个位置。

2 个答案:

答案 0 :(得分:2)

可能大多数选项都是从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不是我经常使用的语言,希望它有所帮助

答案 1 :(得分:1)

通过clojure.java.io/writer发送到make-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."))

@Edward,只有:append:encoding

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