Getting Clojure and Mathematica to communicate under Windows is perhaps slightly easier to set up than it is under Mac and Clojure, but this comes at a price. Because we can't create symbolic links, we can't use Maven to manage the JLink.jar
file. Because of this, we can't use Leiningen to manage our project and its dependencies. Instead, we'll need to download everything and manage the dependencies and classpath on our own.
To prepare for this, we need to download a number of resources, as follows:
Unzip each of these as subdirectories of your project directory. For example, my project directory is named clj-interop
and it contains the subdirectories apache-ant-1.99.4
, Clojuratica-master
, and clojure-1.66.0
.
Of course, you'll also need to have Mathematica (http://www.wolfram.com/mathematica/) installed.
First, we need to get Clojuratica built, and then we'll worry about running Clojure in the right environment in order to be able to talk to Mathematica.
Clojuratica-master
directory and use Ant to build the Clojuratica JAR file:PS C:clj-interop> cd .Clojuratica-master PS C:clj-interopClojuratica-master> ..apache-ant-1.99.4inant jar ... BUILD SUCCESSFUL
PS C:clj-interopClojuratica-master> cd .. PS C:clj-interop> java -cp ".clojure-1.66.0clojure-1.66.0.jar;.Clojuratica-masterclojuratica.jar;C:Program FilesWolfram ResearchMathematica9.0SystemFilesLinksJLinkJLink.jar;." clojure Clojure 1.66.0 user=>
math
macro. Create a file named mma.clj
with contents, as follows:(ns mma) (use 'clojuratica) (import [com.wolfram.jlink MathLinkFactory]) (defn init-mma [mma-command] (defonce math-evaluate (math-evaluator (doto (MathLinkFactory/createKernelLink mma-command) (.discardAnswer))))) (init-mma (str "-linkmode launch -linkname " ""C:/Program Files/Wolfram Research/Mathematica/9.0/MathKernel.exe"")) (def-math-macro math math-evaluate)
user=> (use 'mma) nil