file - Clojure: Equivalent to Common Lisp READ function? -


When I want to read in a S-expression stored in a file in the ongoing Common Lisp program, I do the following : Loads related data in s-expression in file with file name (FILENAME). (With-open-file (stream filename) (read stream))

  (defun load-file (filename) For example, I have the  foo.txt  name Is a file containing S-expression  (1 2 3) , the above function will return the S-expression, as it is said:  (load-file "foo.txt") . 

I am searching and searching and I did not find an equally beautiful solution in the closet any thoughts?

Thanks!

You can do this Example:

  ('[clojure.contrib.io: as IO]) is required (IO / with-in-reader (io / file "foo.txt") (read)); = & Gt; (1 2 3)  

Note that you want to reboot * read-eval * to false first Also keep in mind that the above work is done with the current contract (and it works in about 1.2 when it is released); For Closer 1.1, the same functionality is clojure.contrib.duck-streams < / Code> and clojure.contrib.java-utils namespaces.


Comments