The clojure.java.api package provides a minimal interface to bootstrap Clojure access from other JVM languages. It does this by providing:
clojure.lang.IFn interface.read for reading data using
Clojure's edn readerIFns provide complete access to
Clojure's APIs.
You can also access any other library written in Clojure, after adding
either its source or compiled form to the classpath.
The public Java API for Clojure consists of the following classes and interfaces:
All other Java classes should be treated as implementation details, and applications should avoid relying on them.
To lookup and call a Clojure function:
IFn plus = Clojure.var("clojure.core", "+");
plus.invoke(1, 2);
Functions in clojure.core are automatically loaded. Other
namespaces can be loaded via require:
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("clojure.set"));
IFns can be passed to higher order functions, e.g. the
example below passes inc to map:
IFn map = Clojure.var("clojure.core", "map");
IFn inc = Clojure.var("clojure.core", "inc");
map.invoke(inc, Clojure.read("[1 2 3]"));
Most IFns in Clojure refer to functions. A few, however, refer to
non-function data values. To access these, use deref
instead of fn:
IFn printLength = Clojure.var("clojure.core", "*print-length*");
IFn deref = Clojure.var("clojure.core", "deref");
deref.invoke(printLength);