Clojure + Mathematica
A few people asked how I wrote a webapp using Clojure with Mathematica. The solution is actually quiet simple - Clojure runs on JVM and Java interop (ability to call any Java libraries) works great. Mathematica provides a J/Link Toolkit that allows you to control the Math kernel from Java.
Why Clojure?
You could also use Java and link to Mathematica, but Clojure has the advantages of a functional and dynamic language. I won’t go into the details of Java vs. Clojure. Paul Graham made a good argument for Lisp in Revenge of the Nerds that’s definitely worth reading. Mathematica also includes a Python library for the MathLink library which does not support the newer versions of Python. You could also power Mathematica websites using webMathematica.
2+2 with Clojure and Mathematica
An equivalent of “hello world” program, following is the code performing a simple arithmetic using Mathematica. Note that to run the script, I need to force run JVM in 32-bit mode (using -d32 option) in Snow Leopard because J/Link package does not provide the 64-bit library. To run the script, all you have to do is call java and make sure to include both J/Link and clojure jars.
A Mathematica Webapp
Compojure is a micro web framework that is similar to Sinatra. It is an ideal choice to demo a stock quote webapp get latest stock price using the Mathematica’s FinancialData function.
Result: