Is functional programming relevant to web development? [closed]

Functional programming matches web apps very well. The web app recieves a HTTP request and produces a HTML result. This could be considered a function from requests to pages. Compare with desktop apps, where we typically have a long running process, a stateful UI and dataflow in several directions. This is more suited to OO … Read more

How do Clojure futures and promises differ?

Answering in Clojure terms, here are some examples from Sean Devlin’s screencast: (def a-promise (promise)) (deliver a-promise :fred) (def f (future (some-sexp))) (deref f) Note that in the promise you are explicitly delivering a value that you select in a later computation (:fred in this case). The future, on the other hand, is being consumed … Read more

Common programming mistakes for Clojure developers to avoid [closed]

Literal Octals At one point I was reading in a matrix which used leading zeros to maintain proper rows and columns. Mathematically this is correct, since leading zero obviously don’t alter the underlying value. Attempts to define a var with this matrix, however, would fail mysteriously with: java.lang.NumberFormatException: Invalid number: 08 which totally baffled me. … Read more

How do I find the index of an item in a vector?

Built-in: user> (def v [“one” “two” “three” “two”]) #’user/v user> (.indexOf v “two”) 1 user> (.indexOf v “foo”) -1 If you want a lazy seq of the indices for all matches: user> (map-indexed vector v) ([0 “one”] [1 “two”] [2 “three”] [3 “two”]) user> (filter #(= “two” (second %)) *1) ([1 “two”] [3 “two”]) user> … Read more

Splitting a Clojure namespace over multiple files

Overview Certainly you can, in fact clojure.core namespace itself is split up this way and provides a good model which you can follow by looking in src/clj/clojure: core.clj core_deftype.clj core_print.clj core_proxy.clj ..etc.. All these files participate to build up the single clojure.core namespace. Primary File One of these is the primary file, named to match … Read more

Java to Clojure rewrite

The biggest “translational issue” will probably be going from a Java / OOP methodology to a Clojure / functional programming paradigm. In particular, instead of having mutable state within objects, the “Clojure way” is to clearly separate out mutable state and develop pure (side-effect free) functions. You probably know all this already 🙂 Anyway, this … Read more

Clojure vs other Lisps [closed]

My personal list of reasons for preferring Clojure to other Lisps (p.s. I still think all Lisps are great!): Runs on the JVM – hence gets automatic access to the fantastic engineering in the JVM itself (advanced garbage collection algorithms, HotSpot JIT optimisation etc.) Very good Java interoperability – provides compatibility with the huge range … Read more

Clojure 1.2.1/1.3/1.4 ‘proxy generated in Grails 2.0.0 runtime fails. 1.2.0 is fine

I found an Issue called CLJ-944 on clojure.org. There you can find a fix for ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.lang.Class issue The problem is: that the compiler injects an incorrect cast to clojure.lang.PersistentHashMap. In this case it should probably be cast to a clojure.lang.Associative, the highest common interface having the .containsKey method. Patch … Read more