Creating functions from Mathematica
We can use Mathematica to create functions that we can pass around and call from Clojure, similar to other functions. Moreover, we can also call these functions from within Mathematica and pass them around in Mathematica. As far as each environment is concerned, functions from the other environment are just black boxes that can be called, but even that much is still very useful.
Getting ready
We must first have Clojuratica and Mathematica talking to each other. Either complete the Setting up Mathematica to talk to Clojuratica for Mac OS X and Linux recipe or the Setting up Mathematica to talk to Clojuratica for Windows recipe. Also, we need to call the init-mma
function beforehand.
Also, we must make sure that the Clojuratica namespace is imported into our script or REPL:
(use 'clojuratica)
How to do it…
Here, we'll create a function that simply wraps the FactorInteger
Mathematica function:
(def factor-int (math (Function [x] (FactorInteger x))))
We can...