On Tue, Aug 30, 2011 at 11:18 AM, Matt  Smith <m0sm...@gmail.com> wrote:
> I have been studying patterns or the notion of idiomatic code in
> Clojure.  The code in clojure.core has some good examples of proper
> Clojure code and is well done.  For that reason I was a bit surprised
> at the definition for re-groups:
>
> (defn re-groups [^java.util.regex.Matcher m]
>    (let [gc  (. m (groupCount))]
>      (if (zero? gc)
>        (. m (group))
>        (loop [ret [] c 0]
>          (if (<= c gc)
>            (recur (conj ret (. m (group c))) (inc c))
>            ret)))))
>
> It seems like the loop/recur is non-idiomatic for this usage and could
> be done with either a map or reduce.

Speed is probably the consideration here, assuming this code appears
after the bulk of bootstrap.

> The final implementation with multi-methods seems cleaner to me in
> making it clearer what the intent of the code is while allowing the
> disjoint functionality.  Too bad the result of the defmulti filter is
> not available to the methods.

This suggests that the following might be a useful enhancement to
multimethods: if any particular method is given 1 more argument than
the dispatch function, the last argument will be filled with the
dispatch function's return value if that method is selected.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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