Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spit and Slurp a vector in Clojure

I am trying to spit a vector like [[1 2 3] [4 5 6]] into a file and later slurp it, but when I slurp it I get a string not a vector. Even if I evaluate the string I get, it is still gives a string. I tried to use (vectors slurpt-string) still it give a one element vector containing the string. Any comments?

Thanks in advance.

like image 908
Ali Avatar asked Jan 07 '11 15:01

Ali


1 Answers

clojure.core/read-string

(spit "foo" [[1 2 3] [4 5 6]])

(slurp "foo") ; "[[1 2 3] [4 5 6]]"

(read-string *1) ; [[1 2 3] [4 5 6]]

(type *1) ; clojure.lang.PersistentVector


(read-string "[[1 2 3] [4 5 6]]")

like image 101
MayDaniel Avatar answered Nov 06 '22 21:11

MayDaniel