(for ...) generates a lazy sequence so it isn't realized until after the value is returned from the function. You need to wrap (for ...) with (doall ...) to realize the sequence inside (with-open ...)
On Fri, Aug 12, 2011 at 4:47 PM, turcio <tur...@gmail.com> wrote: > Hi, > I'm trying to write a function which creates file twice as big > compared to the original file by simply duplicating its content. > > It looks like in the for loop I can't even read the first line > although I'm using with-open. Can you tell me what am I doing wrong? > > (defn duplicate-file-data [file-path] > (with-open [reader (clojure.java.io/reader file-path) > writer (clojure.java.io/writer (str file-path 2) :append > true)] > (for [line (line-seq reader) > :let [line-count (count(line-seq > reader)) > curr-line 0] > :when (< curr-line line-count)] > ((.write writer (str line)) > (.newLine writer) > (inc curr-line)) > ))) > > > -- > Thanks > Daniel > > -- > 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 -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Railo Technologies, Inc. -- http://www.getrailo.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- 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