Skip to content

Unexpected behaviour with 'repeatedly' #29

Answered by borkdude
pauldorman asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Paul,

Thanks a lot for your kind words!

The problem is that repeatedly return a lazy sequence and nothing happens unless you realize the sequence:

(defn run-simulation [n]
  (doall (repeatedly n simulation)))

but since you're not using the result, you could also just use dotimes:

(defn run-simulation [n]
  (dotimes [i n] (simulation)))

Your workaround triggered the evaluation of the lazy sequence which is why that worked as well, but it does raise an exception (visible in the developer console).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pauldorman
Comment options

Answer selected by pauldorman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants