Database Reference
In-Depth Information
How to do it…
In Mathematica, we execute a ile using the Get function. Here, we just use Clojuratica to call
this on the appropriate ilename:
user=> (math (Get "line-integral.m"))
(* 2 Pi)
How it works…
This uses the Mathematica function Get , which takes the name of a ile that contains one or
more Mathematica commands. It executes those and returns the value of the last command.
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 irst 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 call it like a regular function, as follows:
user=> (factor-int 1234567890)
[[2 1] [3 2] [5 1] [3607 1] [3803 1]]
 
Search WWH ::




Custom Search