clojure - list comprehension code to txt file -


how dump txt file execution of list comprehension?

   (for [ nr [1 2 3] letter [:a :b :c]] (str nr letter)); generates need 

when adding above code (spit "test.txt" the_above_code) form, have found lazy sequence name (clojure.lang.lazyseq@7d534269).

thank in advance hint/url. dg

ps updating initial post... possible write each generated code on different line?

the following trick:

(spit "test.txt"       (with-out-str          (pr (for [nr [1 2 3] letter [:a :b :c]]               (str nr letter))))) 

whith-out-str allows string whatever printed standard output , pr prints whatever passed in readable format (i.e. works read-string function). combination of these 2 can readable string representation of lazy sequence written file.

edit

in order print each element of list comprehension in different line have both prnint stdout , realize lazy sequence doall or someting of sort. although if only creating sequence printing elements doseq more suitable , idiomatic:

(spit "test.txt"       (with-out-str         (doseq [nr [1 2 3] letter [:a :b :c]]           (prn (str nr letter))))) 

test.txt

"1:a" "1:b" "1:c" "2:a" "2:b" "2:c" "3:a" "3:b" "3:c" 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -