> (reduce (fn [model f] (assoc model f (inc (get model f 1))))
>        {} features))

> Do Clojurians usually arrange like that? Can it be rearrange for more
> understandability?

I would write it exactly like that. What happens as you become
familiar with Clojure is that the patterns of the api become almost
stamped on your brain, something like a set of nested boxes. When you
see a piece of code that starts with "(reduce" your mind immediately
forms a kind of template like;
... reduce [
   a_function_with_2_args,
   the_initial_thing_to_be_reduced_into,
   the_coll_to_be_reduced
]
and you just know that the 2 args of the function are;
... [the_thing_being_reduced_into_at_each_step,
     the_element_of_the_coll_at_each_step
   ]
and that it should return;
... _the_coll_being_reduced_at_each_step
which will be the final result of the "(reduce"

Similarly your mind then "chunks" the function's contents and applies
a similar pattern matching process to that.

This ability just comes with practice and continual use of the
language and the best (perhaps only) way of acquiring it is by
experimenting with these main core api calls (reduce, map, assoc,
update-in, loop, etc) at the repl.

It's like driving a car, once you can drive you just use the api
(clutch, accelerator, gears, etc) without having to think where the
bits are and that you have to press the clutch before changing the
gears. You would simply ignore, or be irritated with labels that said
"Clutch Here", "Brake Here" and so on.

This is not meant to be patronising, but I think it does speak to the
problem of "disjoint" between experienced Clojure/Lisp'ers and noobs
learning the language. They tend to code as above, but when trying to
help people who are learning, they try to bridge the (imperative) gap
by breaking down the code, adding let placeholders, etc. But they
don't code like that.

Not sure what the best way of bridging the gap is and it is
patronising to just say "experiment at the repl", but for me
personally, that was how the patterns started "clicking" in.

Perhaps our learning resources should include examples like the above
to help learners at least see what the patterns are?

-Rgds, Adrian.

-- 
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

Reply via email to