Hi,

Am 16.08.2011 um 17:26 schrieb Thomas:

> I have been struggling with this, hopefully, simple problem now for
> quite sometime, What I want to do is:
> 
> *) read a file line by line
> *) modify each line
> *) write it back to a different file
> 
> This is a bit of sample code that reproduces the problem:
> 
> ==========================================================
> (def old-data (line-seq (reader "input.txt")))
> 
> (defn change-line
>    [i]
>    (str i " added stuff"))
> 
> (spit "output.txt" (map change-line old-data))
> ==========================================================
> #cat "output.txt"
> clojure.lang.LazySeq@58d844f8
> 
> Because I get the lazy sequence I think I have to force the execution?
> but where
> exactly? And how?

spit does not take a sequence of lines. Hence you'll have to do something like 
this:

(->> old-data
  (map change-line)
  (interpose \newline)
  (apply str)
  (spit "output.txt"))

Sincerely
Meikel

-- 
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

Reply via email to