Sean Corfield <[email protected]> writes:
> Most of my comments would be true of code in other languages (and
> Scala came to mind, specifically, as I was suggesting breaking code
> into smaller units to aid readability). I'm interested in hearing more
> about the sort of functions that begin "by unpacking and computing a
> large number of values that are all important for subsequent
> computations". I'm not seeing this in my code so I assume we're
> working on very different problem domains - could you elaborate?
I see this every so often, but it's usually easy to solve with partial.
(defn write-jar [project out-file filespecs]
(let [manifest (make-manifest project)]
(with-open [jar-os (-> out-file
(FileOutputStream.)
(BufferedOutputStream.)
(JarOutputStream. manifest))]
(doseq [filespec filespecs]
[HUGE GLOB OF CODE THAT USES project AND out-file]))))
The doseq call needed to be converted to a reduce so it could accumulate
some state, but the big glob of code to be extracted needed access to
the `project` and `out-file` locals. Reducing with a partially-applied
function makes this work nicely:
(defn write-jar [project out-file filespecs]
(let [manifest (make-manifest project)]
(with-open [jar-os (-> out-file
(FileOutputStream.)
(BufferedOutputStream.)
(JarOutputStream. manifest))]
(reduce (partial copy-to-jar project jar-os) #{} filespecs))))
Just a thought. I can see where Mark is coming from, but I don't think
the workaround is particularly difficult or onerous.
-Phil
--
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