Clojure 1.5
groups.google.com
groups.google.com
Another slightly interesting thing is the sudden enhancement to read-eval and EDN[2]. That's mainly because of the rough weather Ruby/Rubygems was in with the YAML-exploits, which caused a heated discussion on how the Clojure reader should act by default[3][4].
[1]: http://www.infoq.com/presentations/Clojure-Reducers
[2]: https://github.com/clojure/clojure/blob/master/changes.md#21...
[3]: http://dev.clojure.org/jira/browse/CLJ-1153
[4]: https://groups.google.com/d/topic/clojure-dev/zG90eRnbbJQ/di...
(reduce
(fn [a b]
(if (> a 100) (reduced a) (+ a b)))
(range 100000))
=> 105
I've often had to use loop/recur instead of reduce because you could not short circuit. No longer.If you're interested in keeping up with clojure news, I recently started a clojure newsletter where we cover this sort of thing: http://defnewsletter.com
It would probably be better to pitch that our angle is code-heavy rather than news-heavy. Thanks for this feedback. Also, A drip of Javascript is really cool. I just subscribed.
Both Javascript weekly and Ruby weekly periodically cover idioms of their respective languages, I like those. Ruby Weekly seems to have more posts about code refactoring and style, which I also appreciate.
These sound like a really good thing, but what if I want to use map and not reduce? Is Clojure smart enough to understand that some other function not named reduce should be transformed the same way?
[bin]$ lein version
Leiningen 2.0.0 on Java 1.7.0_15 Java HotSpot(TM) Client VM
[bin]$ lein repl
nREPL server started on port 41384
REPL-y 0.1.9
Clojure 1.4.0
I understand that Clojure is just a jar dependency, just need to find where lein's dependencies specified...For a new project I would have specified Clojure 1.5 in defproject, but for REPL?
It also occurs to me that threading through `some->` and `some->>` is kind of like doing computations in the Maybe monad in Haskell.
I eventually want to move on beyond ruby and java and try out a functional language. Clojure, Scala and Haskell all seem interesting. Haskell because it's pure functional. Scala and Clojure because they're functional and on the JVM, and out of the two, Clojure.
So it's between clojure and haskell in my mind. Haskell has a great tutorial book/website (http://learnyouahaskell.com/). Is there a great resource like this for clojure? (obviously there are many books, but what's the best, and ideally, does it have a free online version that I can try out before buying)
http://stevelosh.com/blog/2012/07/caves-of-clojure-01/
All parts:
This should be a nice follow-up.
I like it so far because it relates many new functional programming concepts back to ideas from other languages. In the early portions of the book it frequently shows ruby, java, and python code alongside a line of clojure.
A more interactive way to try out the language would be to try www.4clojure.com or the clojure koans. Both take different approaches to giving you puzzles to solve with clojure.
In addition to that I'd add:
- Clojure because it's a Lisp dialect (and if you've never learned any Lisp, then it's good to add that to your skillset too)
- Clojure because it also targets other runtime, like say browsers JavaScript engine. ClojureScript looks really interesting and I'm sure we'll some very interesting things in ClojureScript very soon
- Clojure because it has STM
Now honestly between Clojure and Haskell I'd say that you should really learn both.
I'm getting quite OK with Clojure. Now I definitely need to find the time to learn Haskell...
lein run myscript.clj
and then sit there waiting for 2 - 3 seconds to see your result. Might sound insignificant but it's noticeable when you're constantly switching between source and result. Obviously the way to get around this is to load everything into a REPL and enjoy the advantages of explorative programming.This is where Haskell has an advantage, the runghc command is very fast, and compiling your script/program into a static binary means it's quick to execute as well.
Clojure (and Scala) need to sort out the JVM warmup to make them viable general purpose languages.
The bizarre thing is, running Java on the JVM startsup almost instantly.
From a web application background, are performance gains seen because of clojure's concurrency?
Having to state "do this in parallel" (by using clojure.core.reducers fns instead of their clojure.core counterparts) is not automatic but explicit parallelization.
I believe that the idea of a compiler that will infer the parallelizable parts of your code crosses the limits of computability.
Before reducers, I'd have said that Obj-C's blocks with GCD was the closest thing to "automatic parallelization" (in that you could get concurrent execution without the need to handle explicit concurrency primitives). The problem, of course, is that writing C/Obj-C with closures is a non-trivial shift in design. With Clojure, the way that code is currently written is already well positioned to benefit from reducers.
I suppose there should always be an escape hatch to explicitly choose either of the two for a specific piece of code, but the default could be "JVM, please choose what's best for my code".
Generally, the part of a program worth parallelizing is pretty obvious: that that is long-running, must process lots of data, etc. Most calls to map/reduce/filter in the average (Clojure) program are nothing like that.
Finally and AFAICT, ForkJoin can do actually worse than a simple FixedThreadPool (as used by clojure.core/send) for workloads that are "symmetric" and not particularly divisible in subtasks.
Thank you all.
[1]http://stackoverflow.com/questions/4058430/how-well-does-clo...