Hi,

Am 02.03.2009 um 06:06 schrieb max3000:

Here is the code that gave me trouble:

   (map #(add-watch % watcher callback-fn) all-agents)

This was not executing. I had to change it to the below expression:

   (doseq [agent all-labor-agents]
     (add-watch agent total-labor-agent callback-fn))

This second expression seems less elegant than the map above.

The unhelpful answer: Do it the right way! Neither map nor for
are looping constructs.

The (hopefully) more helpful answer: The second expression
looks much more elegant than (dorun (map ...)). Let me explain
why I think so.

The map produces a list of nils, which you throw away. This is
waste. I come from Germany and here it's a big deal with recycling
and resource saving. So I find such a waste deeply ugly.

On the other hand doseq just iterates eager through the sequence
evaluating the body and finally returning nil.

Emphasising the difference between functional code and code
living from side-effects is a very strong point of Clojure. Laurent
already gave some hints to recognise side-effecting functions.
So whenever you have such a smell, look for the do* functions,
doall, doseq, do itself, ...

There were already many answers and good ideas (check
usage of lazy return values) in this thread. But I thought, one
should also show that doseq is not ugly.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to