We can use Mathematica to create functions that we can pass around and call from Clojure just like other functions. Moreover, we can also call them from within Mathematica and pass them around in Mathematica.
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, you'll need to have the init-mma
function called.
Also, make sure that the clojuratica
namespace is imported into our script or REPL.
(use 'clojuratica)
Here, we'll create a function that simply wraps the Mathematica function FactorInteger
.
(def factor-int (math (Function [x] (FactorInteger x))))
We can call it like a regular function.
user=> (factor-int 1234567890) [[2 1] [3 2] [5 1] [3607 1] [3803 1]]