3 ms·
You can redirect I/O in Clojure, so you possibly can spit/slurp things other than files. I was sure you could use with-input-stream and with-output-stream but I
by dkersten 17y ago
You can redirect I/O in Clojure, so you possibly can spit/slurp things other than files. I was sure you could use with-input-stream and with-output-stream but I don't see it now.. oh well. Anyway, this (taken from Wikipedia) works with standard I/O and I can only assume ti works with file I/O too (if not, then I agree this is a flaw in the Clojure library design):
(def bit-bucket-writer
(proxy [java.io.Writer] []
(write [buf] nil)
(close [] nil)
(flush [] nil)))
(defmacro noprint
"Evaluates the given expressions with all printing to *out* silenced."
[& forms]
`(binding [*out* bit-bucket-writer]
~@forms))
(noprint
(println "Hello, nobody!"))
In any case, I see nothing wrong with having these things part of the library. Sure, you could write them yourself, but everyones busy these days, so common tasks should come packaged with the language in the form of a standard library. This is one thing that attracted me to Clojure - an extensive library (and even more so if you count the Java libraries that you get with it, at little extra effort).