Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time). Sample Ruby code to give you the idea:
dates = x.times.collect { print "Enter date: "; Date.parse(gets.chomp) }
Just for the heck of it, I wrote the script in Clojure, and wound up using some rather ugly code with swap!
and loop...recur
. I'm wondering what the cleanest way to achieve the desired effect in Clojure would be. (Clojure does have dotimes
, but it doesn't retain the values returned from evaluating the body... as might be expected from a language which emphasizes pure functional programming.)