On Fri, Jan 6, 2012 at 9:25 AM, Matthew <matthewg....@gmail.com> wrote: > (defn id3-encode > ([] (id3-encode test-out)) > ([file] > (with-open [out (-> (File. file) (FileOutputStream.) > (BufferedOutputStream.) (DataOutputStream.))] > (binding [*out* out] > (map #(write-a :byte %) [\I \D \3]))))) > > When i run the id3-encode function I get this exception: > > user=> (fixlkg.fix/id3-encode) > > (user=> IllegalArgumentException No matching method found: writeByte > for class clojure.lang.Var$Unbound > clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:52)
Looks like laziness. If you don't use the return values from write-a then you should probably change (map #(write-a :byte %) [\I \D \3]) to (doseq [c [\I \D \3]] (write-a :byte c)) though an alternative is just to wrap the map expression in (dorun ...). If you do use the return values, wrap in (doall ...): (doall (map #(write-a :byte %) [\I \D \3])) The latter will cause the whole sequence of write-a return values to be held in memory at once. In this case you only have three such values, but I suppose you might have a larger job in reality than the short one you posted here with your query, or that your real code may return large objects from each call. All three modifications will ensure the writes take place inside the dynamic scope of the binding (and the surrounding with-open!). -- 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