First of all, your function works great for many inputs:
Clojure 1.3.0 user=> (defn writelines [file-path lines] (with-open [wtr (clojure.java.io/writer file-path)] (doseq [line lines] (.write wtr line))))
However, when you try to convey something strange, we get the error you described:
user=> (writelines "quux" [#{1}]) IllegalArgumentException No matching method found: write for class java.io.BufferedWriter clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:79)
This error is due to the fact that BufferedWriter has several overloaded versions of write and clojure does not know which one to call. In this case, write(char[]) and write(String) are conflicting. With inputs like strings ( "a" ) and clojure integers ( 1 ), it was known that he was calling the version of the String method, but with something else (like clojure set, #{1} ) clojure couldn't solve .
How to guarantee that the writelines inputs writelines really String or their string use with the str function?
Also see the spit function .
source share