This doesn't feel like the author is trying to actually help Java programmers, but rather is just an excuse for him to patronizingly describe a language to those he considers less fortunate.<p>I also don't understand the reason for writing the code in an intentionally non idiomatic style. If you want to convince someone why something is better; show them how it would be done properly. The way it has been presented instead insults the audiences intelligence by presupposing that they would be unable to understand this material, that the author has admittedly only recently picked up himself.<p>I don't think (reduce min list) is going to blow anyone's mind, and writing a function to iterate through the indexes of a list will do more to confuse than to enlighten.<p>not to mention; we've been here before haven't we - <a href="http://c2.com/cgi/wiki?SmugLispWeenie" rel="nofollow">http://c2.com/cgi/wiki?SmugLispWeenie</a>
This is an bad example of macros; they're completely unnecessary here. The only thing you're stepping around is the already reader-macro shortened (function <). If you want to show off macros I think you should do it with something that simply cannot be done without them. Otherwise you end up with these pissing matches in the comments and the discussion diverges entirely away from metaprogramming to talking about characters or lines of code saved, which is kind of not that interesting. And Java vs Lisp is already kind of a tired topic. (Lisper and card carrying Java-hater here)
Sigh. A good Java coder will also "get itchy" when writing two such similar functions. In fact, they'll probably already have a library that provides predicates that make the same level of abstraction trivial. Sure, the code in the predicate, being a whole class, will be a bit verbose, but that's a separate issue.
It can be written more concisely with fold.<p><pre><code> $ ghci
Prelude> let getFromList ls pred = foldl (\x y -> if x `pred` y then x else y) (head ls) (tail ls)
Prelude> getFromList [1..10] (<)
1
Prelude> getFromList [1..10] (>)
10</code></pre>
That's funny... I posted a few alternate java examples to his blog but it looks like the comment was rejected.<p>(Perhaps because I said the lisp looked like vomit? but it does!)<p>int getMax(int... list) {
int max = list[0];
for (int i : list) max = Math.max(max, i);
return max;
}<p>or if you have a collection
Collections.min(list);