Skip to content

UseInClojure

Joseph Lizier edited this page Aug 20, 2015 · 1 revision

How to use the toolkit in Clojure

Use in Clojure

The Java code from this toolkit can easily be used in Clojure -- the project jar has been deployed to maven as me.lizier/jidt for automated inclusion in clojure projects (see further details below).

Here we give only a brief overview of calling Java code from Clojure; several longer examples of using the JIDT toolkit in Clojure can be viewed at Clojure_Examples.

Using Java objects in Clojure

No special installations are required to begin using Java objects in Clojure, these are supported natively as described here.

You can run your Java code in Clojure as follows:

  1. Add the ["LATEST"](me.lizier/jidt) for the latest version (or name a specific version) to the :dependencies vector of your project.clj file (this automatically references the JIDT jar from the leiningen repository and pulls it in). See our sample project.clj file in our Clojure_Examples.
  2. Import the classes you wish to use, e.g. (import infodynamics.measures.discrete.TransferEntropyCalculatorDiscrete).
  3. Create an instance of the calculator you wish to use, e.g. (def teCalc (TransferEntropyCalculatorDiscrete. 2 1))
  4. Call methods on the object, e.g. (.addObservations teCalc sourceArray destArray).

Array conversion -- is generally straightforward -- see some details at the Clojure-Java interoperability documentation, and the use of int-array, into-array and map in our Clojure_Examples.

Acknowledgements

A big thank you to Matthew Chadwick for showing me how to do this and getting things up and running with clojure and leiningen.

Clone this wiki locally