Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out allowed options for the Clojure-function (spit)?

The Clojure-function spit allows to write data into files, e.g.:

(spit "filename.txt" "content")

It also allows to add content to existing files.

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

In the documentation ((doc spit)) it only says that options can be passed to the clojure.java.io/writer. But (doc clojure.java.io/writer) does not list allowed options. So is there a "detailed-mode" for documentation available?

I found the :append-option via http://clojuredocs.org/clojure.core/spit , but I'm sure it is also listed somewhere in the documentation.

like image 949
Edward Avatar asked Oct 21 '14 10:10

Edward


People also ask

How do you define a list in Clojure?

List is a structure used to store a collection of data items. In Clojure, the List implements the ISeq interface. Lists are created in Clojure by using the list function.

What does FN mean in Clojure?

They can be assigned as values, passed into functions, and returned from functions. It's common to see function definitions in Clojure using defn like (defn foo … ​) . However, this is just syntactic sugar for (def foo (fn … ​)) fn returns a function object.

What is slurp in Clojure?

The slurp command opens a reader on a file and reads all its contents, returning a string. Following is an example of how this can be done. (ns clojure. examples. hello (:gen-class)) ;; This program displays Hello World (defn Example [] (def string1 (slurp "Example.txt")) (println string1)) (Example)

What is a Clojure form?

Clojure (/ˈkloʊʒər/, like closure) is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system.


2 Answers

Probably most of the options are mapped from Java underlying libraries

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

By browsing the source code I confirm that :encoding is legal

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\".

I cannot help further as Java isn't my more frequently used language, hope it helps

like image 163
Jaime Agudo Avatar answered Sep 30 '22 17:09

Jaime Agudo


via clojure.java.io/writer to make-writer, so found it in 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, there are just :append and :encoding

@Jaime Agudo's answer is right, I'd not saw his answer :-(.

like image 30
南山竹 Avatar answered Sep 30 '22 15:09

南山竹