Zac Bir 2019-10-10T17:59:39.000900Z

I’ve got an update function that I want to create a circle, expand it to its largest valid size, and hand that back for the draw function.

(defn update [state]
  (loop [circle {:x (* (rand) width) :y (* (rand) height) :r 1}]
    (when (not (is-valid? circle))
        (conj circles circle)
        circle) ; Hand back our circle to be drawn
      (recur {:x (:x circle) :y (:y circle) :r (inc (:r circle))}))))

Zac Bir 2019-10-10T18:00:24.001800Z

However, this function returns nil. What’s the best (both idiomatic and, well, working) approach for what I’m looking for?

Zac Bir 2019-10-10T18:01:12.002700Z

(basically, we’re ignoring the incoming state, creating a new circle each time, comparing its validity (not having grown outside the bounds of the canvas, nor overlapping any other circles)

Zac Bir 2019-10-10T18:26:42.003400Z

Figured it out. s/when/if/

Zac Bir 2019-10-10T19:01:26.004100Z

After more noodling, I’m closer, but my is-valid? function seems to not quite be working 🙂

Zac Bir 2019-10-10T19:01:43.004200Z

Zac Bir 2019-10-10T19:12:44.004900Z

More likely, it’s my behavior in the loop after I’ve tested.