5 ms·
Java.next() - Clojure: The Return of the Lispers
The third chapter of Java.next() series. A glance at the Clojure programming language, a modern Lisp-1 dialect for the JVM and .Net.
- d0m 15y agoI feel like when people are comparing languages, they are exaggerating.. For instance: public boolean hasUpperCase(String word) { if (word == null) { return false; } int len = word.length(); for (int i = 0; i < len; i++) { if (Character.isUpperCase(word.charAt(i))) { return true; } } return false; } or public boolean hasUpperCase(String word) { if (null != word) return any(charactersOf(word), new Predicate() { public boolean apply(Character c) { return isUpperCase(c); } }) else return false; }
- swannodette 15y agoSmall inconveniences add up fast. For example https://github.com/clojure/core.logic/blob/master/src/main/clojure/clojure/core/logic/minikanren.clj https://github.com/clojure/core.logic/blob/master/src/main/c.... It's a 1000 lines of Clojure, I strongly doubt that this could be implemented in anything less than 5000 lines of Java split across 10 files.
- efsavage 15y agoI'd love to be sold on a new language, but using it by showing me ridiculous examples of a language I know reduces the credibility of the seller. It's an otherwise good looking article but when I see this: public boolean hasUpperCase(String word) { if (word == null) { return false; } int len = word.length(); for (int i = 0; i < len; i++) { if (Character.isUpperCase(word.charAt(i))) { return true; } } return false; } Where it should be this: public boolean hasUpperCase(String word) { return word != null && word.matches(".*[A-Z]+.*"); } It casts doubt on the other examples. I'm not saying Java isn't a verbose language that can get tedious, but let's use some decent examples.
- swannodette 15y agoIt's doesn't cast doubt on the examples at all, your code is less generic: (defn has-uppercase? [string] (some #(Character/isUpperCase %) string)) This code can deal with any sequence of characters: String, Array, PersistentList, PersistentVector, Cons, LazySequence, etc. Your example only deals with String.
- efsavage 15y agoFair enough, but mine was not an alternate to his Clojure code, but to his Java code (which only checks String). Perhaps he should have focused on the functional efficiency like you did, rather than just bloated lines of code.
- seabee 15y agoIt's still not an alternate to the Java, since there are more upper-case characters than the 26 your regex matches. But I'm sure there is an appropriate Unicorn character class you could use instead.
- palish 15y ago... A String is a sequence of characters. Why would you want a "list of characters"? That's called a String.
- barrydahlberg 15y agoUseful if you are composing the function with others which may not be built specifically for strings, e.g. filter, map etc.
- Nrsolis 15y agoI'm with you. The author doesn't appear to be very experienced in any of these languages. He just seems to be posting his own naive interpretations. That said, I'm really excited about Clojure. I got back into programming via Ruby and now Clojure is getting me back into data structures.
- th0ma5 15y agoI've been playing a lot with Kawa (Scheme) for Java, it's rather nice.
- mahmud 15y agoAt this point, Clojure is the it Lisp on the JVM.
- rikthevik 15y agoWhat are the cool things we should know about Kawa?
- cjenkins 15y agoOne cool thing is that the Google Android App Inventor is built out of Kawa. (http://en.wikipedia.org/wiki/Google_App_Inventor http://en.wikipedia.org/wiki/Google_App_Inventor) I believe Kawa is also currently a bit friendlier on Android as Clojure has some overhead. (More at http://dev.clojure.org/display/design/Android+Support http://dev.clojure.org/display/design/Android+Support)
- dotcomsmarties 15y agoI've been coding Java/Python for 10+ years (C/C++ before that), and recently started on Clojure a few months ago. I'm having trouble grokking Clojure since I'm not a Lisp guy, but after stumbling around like a blind rat I find that Clojure's syntax is quite extraordinary. I hope Clojure will become more mainstream as more people use them, and creates more tutorials for a layman like me.