Hi all,
There is an omission in the core clojure library: there is no way to create a file reader. I follow the scheme of regex: all the verbosity of java.util.regex.* classes is hidden away, in a beautiful set of small (and heavily used) functions. For file I/O, though, core clojure has functions that deal with readers, like for example line-seq, but there is not a single function to create a reader trivially. Currently, one must resort to incantations like: (with-open [stream (java.io.BufferedReader. (java.io.FileReader. "/home/albert/test.xml"))] (doseq [line (line-seq stream)] (println line))) ... which require writing in imports or fully qualified names for java classes whose existence I wish I could forget about. In order to use clojure from a REPL, just like I'd use Matlab or R or similar programs, a file-reader generator is missing. Every clojure user is going to have to reinvent the wheel, in the form of custom code in the user.clj to avoid excessive and avoidable typing. I understand one of the main problems is the required ".close" call on the reader, which so far is taken care of by the macro with-open. So: why not have a file-reader function in core clojure, that MUST be invoked from within a with-open macro (or throws an exception)? This would be the same scheme of dosync and alter/commute/etc. Then we'd write: (with-open [rdr (file-reader "/home/albert/test.xml")] (doseq [line (line-seq stream)] (println line))) The above would only be necssary when lazyness is a requirement. So, even better, in the spirit of the do-it-all "slurp" function, how about a non-lazy (hence no ".close" call issue) slurp-lines function? (Sure, one can write (vec (.split (slurp "/home/albert/test.xml") "\n")) but that again implies one knows the java API by heart.) Adding the above 2 functions and moving spit from clojure-contrib into core would finally make the clojure REPL a great REPL for text data I/O, and thus for data analysis in a research lab. Albert -- Albert Cardona http://albert.rierol.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---