Fork me on GitHub
#beginners
<
2017-02-10
>
alexlykos12:02:12

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?

schmee12:02:03

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.

alexlykos12:02:32

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