I agree that this seems a bit terse and magical. However, there are a couple of mitigating factors to consider.
1. frequencies is a Clojure core function. It's simple enough to understand on its own, but if you haven't encountered it, you'd need to look it up to be sure what it's returning. Someone who's seen a lot of Clojure code has probably already encountered it. 2. mapcat is a classical LISP function. The name is retroactively obvious, but if you haven't seen it, it does a lot of stuff at once. 3. The rest of this function is basically a sequence comprehension, which is idiomatic in Clojure. 4. The example you have chosen isn't the final version. You have selected a partial solution and are presenting it as a straw man. Those bare constants go away on the next page. If I were writing this code, I might break down the long line a bit - the mapcat and frequencies calls could be placed into a let binding and given meaningful names, which would aid somewhat. Apart from that, you're contending with the fact that Clojure (and LISPs) is (are) wide, shallow languages. You have lots and lots of little functions that make it up. Without knowing what these do, the whole language can seem impenetrable. On Wednesday, April 10, 2013 1:27:58 PM UTC-4, edw...@kenworthy.info wrote: > > So, page 143 of Clojure Programming has an implementation of Conway's Life: > > (defn step > "Yields the next state of the world" > [cells] > (set (for [[loc n] (frequencies (mapcat neighbours cells)) > > :when (or (= n 3) (and (= n 2) (cells loc)))] > > loc))) > > The book claims this to be "an elegant implementation'. > > Now it's been a long while since I wrote code to put food on the table - > but back then if I saw C or C++ code written like this I would describe it > as obfuscated - the sort of thing I would expect to see in the (now > defunct?) annual obfuscated C competition. It's concise and rather clever, > certainly, but hardly self-documenting: it's not very clear what it's doing > at all- with a couple of magic numbers thrown in for good measure. Rather > arcane in fact. > > Is it just me? Is this considered to be good Clojure code and I'm just > hopelessly out of touch and need to get with the programme? > > > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.