On Sat, Jan 8, 2011 at 2:09 PM, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> 2011/1/8 Ken Wesson <kwess...@gmail.com>
>>
>> On Sat, Jan 8, 2011 at 12:33 PM, Stuart Halloway
>> <stuart.hallo...@gmail.com> wrote:
>> > One goal of resource scopes [1] is to help with scoping activities at
>> > the REPL. That said, I think this is a "ramping up" problem -- I rarely if
>> > ever hit it anymore.
>> >
>> > Stu
>> >
>> > [1] http://dev.clojure.org/display/design/Resource+Scopes
>>
>> Eww.
>>
>> The more I think about it, the more I'm convinced that it's far
>> preferable to use a pure functional approach. Instead of fixing
>>
>> (defn foo [x]
>>  (with-open [bar (baz x)]
>>    (make-some-lazy-seq bar)))
>>
>> (map do-something-with (foo quux))
>>
>> -> IOException: stream closed
>>
>> with "resource scopes", or even with
>>
>> (defn foo [x]
>>  (with-open [bar (baz x)]
>>    (doall (make-some-lazy-seq bar))))
>>
>> (map do-something-with (foo quux))
>>
>> isn't the truly functional way to use HOF like this?
>>
>> (defn foo [x processor]
>>  (with-open [bar (baz x)]
>>    (processor (make-some-lazy-seq bar))))
>>
>> (foo quux #(map do-something-with %))
>
> With the implicit assumption that your processor is not lazy itself ...

Yes, obviously. I figure it could be anything from (doall (take 5
...)) to (reduce #(assoc ...) {} ...) or whatnot, resulting in a
number, a map, a short eager seq, or some such. After all you are
querying the file for something, boiling it down to something, aren't
you? (first (filter identity (map #(re-matches ...) (line-seq ...))))
perhaps, to emit the first occurrence of some pattern in a text file?
Whatever.

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