On Nov 27, 3:59 am, Gerrard McNulty <[email protected]> wrote: > Hi, > > I've a head holding problem that I believe is a bug in clojure 1.3. I > wrote the following function to split a a lazy seq of strings across > files of x size: > > (defn split-file > ([path strs size] > (trampoline split-file path (seq strs) size 0)) > ([path strs size part] > (with-open [f (clojure.java.io/writer (str path "." part))] > (loop [written 0, ss strs] > (when ss > (if (>= written size) > #(split-file path ss size (inc part)) > (let [s (first ss)] > (.write f s) > (recur (+ written (.length s)) (next ss)))))))))
The Clojure compiler can't in general clear closed-over variables such as 'ss in in #(split-file path ss ...) because the closure could be called more than once. You could try using an (undocumented, compiler internal) feature to give more information: (^:once fn* [] (split-file path ss size (inc part))) instead of #(split-file ...) and change the call to trampoline to (trampoline (^:once fn* [] (split-file path (seq strs) size 0))) since the multi-argument version of trampoline doesn't appear to use ^:once. -- Juha Arpiainen -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
