3 ms·
This is a sound article - Clojure's laziness is often a source of common gotchas for new users of the language. It's often not clear what is lazy and what isn'
by djtango 9y ago
This is a sound article - Clojure's laziness is often a source of common gotchas for new users of the language.
It's often not clear what is lazy and what isn't - concat is lazy for instance. It isn't externally obvious which of the very common operations are lazy, filter being lazy has bitten me in CLJS a few times too.
Adding to the source of the confusion is that the REPL will often realize your side-effects which then won't get evaluated in your runtime environment.
One of the errors I used to make earlier on was:
(map insert-into-db table-rows)
- serpix 9y agoalways mapv when doing I/O on the backend and always extra vec when returning sequences in the frontend
- joncampbelldev 9y agorun! and doseq are for IO on each element of a sequence. Functions like mapv are intended for data transformation, not side-effects. This is why run! and doseq return nil
- djtango 9y agoI don't often find myself doing sequential side effects so often anymore, but when I do doseq has been my go to, though I will confess I didn't know about run! until this thread.