Fork me on GitHub

Hi, I have a question, I want to write a loop which includes side effects but also computes a value at end of each iteration, it actually includes some println calls to show the progress/status at command line as well some api_calls. The final api_call inside the loop each time returns a value which is the computation result which I want to keep, something like for the first iteration :id 1 :result 100, for the second :id 2 :result 200 etc. maybe in a sorted map or anything else. So initially I wrote it with dotimes but then I see it is mostly intended for side effects, I thought to use atom to save each time the computed value but then I am not sure how good is as a practice. Then I looked up the for function as it returns a list, but looking the examples I get the impression it is not intended for side effects, so I am not sure what to use. Should I use loop-recur or something else?


alexlykos for should not be used exclusively for side effects. In those cases you are better of using dotimes, run or something else meant for that purpose. It is totally fine to have a println in a for, if that for also returns values.


oh ok, thanks a lot, I will try with for.