Clojure: Equivalent to Common Lisp READ function?

Posted by jkndrkn on Stack Overflow See other posts from Stack Overflow or by jkndrkn
Published on 2010-05-18T00:56:24Z Indexed on 2010/05/18 1:00 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

Hi there.

When I want to read in an S-expression stored in a file into a running Common Lisp program, I do the following:

(defun load-file (filename)
  "Loads data corresponding to a s-expression in file with name FILENAME."
  (with-open-file (stream filename)
    (read stream)))

If, for example, I have a file named foo.txt that contains the S-expression (1 2 3), the above function will return that S-expression if called as follows: (load-file "foo.txt").

I've been searching and searching and have not found an equally elegant solution in Clojure. Any ideas?

Thanks!

© Stack Overflow or respective owner

Related posts about clojure

Related posts about read