clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
genekim 2020-11-16T17:28:37.086600Z

So many great insights in the latest podcast! Thanks @nate and @neumann !! Doseq! I finally understand!

👍 1
neumann 2020-11-16T17:50:52.086700Z

@genekim That's great to hear! You're welcome! For me, dorun has been the most baffling. I'm sure there is a great use case for it out there, but I still haven't found it useful in production code.

Bob B 2020-11-16T19:00:58.090400Z

One little laziness 'corner case' (maybe) that I've stumbled over once or twice is that using something lazy in a recur can lead to a StackOverflow for a sufficiently large number of recursions. For example, if you (recur (map inc coll)), that can SO, but throwing a doall in there (or using mapv if you can work with a vector) eliminates it

Bob B 2020-11-16T19:17:37.090500Z

this is 100% speculation, but looking at core.clj, doall is defined in terms of dorun, so the impression that I get is that dorun can process the whole seq, even if the whole seq doesn't fit in memory, while doall is basically "dorun and then return the realized seq" (which of course means the whole realization needs to fit in memory). and apparently run! was introduced in 1.7, so perhaps dorun was more directly useful before its introduction

lodin 2020-11-16T21:35:57.092400Z

@highpressurecarsalesm Are you by any chance using concat in that function? If so, then that is probably the culprit, not recur.

Bob B 2020-11-16T21:37:32.092500Z

nope... here's a trivial repro (it's obviously not useful code):

(loop [a [10000]]
    (if (zero? (first a))
      a
      (recur (map dec a))))

lodin 2020-11-16T22:02:51.092800Z

Ah, yeah. That stacks thunks and will SO.