Friday, 23 August 2013

using with-open to initialize unknown number of readers/writers in Clojure

using with-open to initialize unknown number of readers/writers in Clojure

Say that I have a file to be used by n readers and m writers. When I know
n and m's value, say if n==3 and m==1, I could write a code like this:
(use 'clojure.java.io)
(with-open [rdr1 (Reader file)
rdr2 (Reader file)
rdr3 (Reader file)
wtr1 (Writer file)]
(time-to-work-out-guys))
Now the case is, the app user determines values of n and m, so I have no
idea what value n and m would have. Is there any way that I still can use
with-open to initialize readers/writers and do the job?

No comments:

Post a Comment