clojure.java.api
Class Clojure

java.lang.Object
  extended by clojure.java.api.Clojure

public class Clojure
extends Object

The Clojure class provides a minimal interface to bootstrap Clojure access from other JVM languages. It provides:

  1. The ability to use Clojure's namespaces to locate an arbitrary var, returning the var's IFn interface.
  2. A convenience method read for reading data using Clojure's edn reader

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 plus to read:

 IFn map = Clojure.var("clojure.core", "map");
 IFn inc = Clojure.var("clojure.core", "inc");
 map.invoke(inc, Clojure.read("[1 2 3]"));


Method Summary
static Object read(String s)
          Read one object from the String s.
static IFn var(Object qualifiedName)
          Returns the var associated with qualifiedName.
static IFn var(Object ns, Object name)
          Returns an IFn associated with the namespace and name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

var

public static IFn var(Object qualifiedName)
Returns the var associated with qualifiedName.

Parameters:
qualifiedName - a String or clojure.lang.Symbol
Returns:
a clojure.lang.IFn

var

public static IFn var(Object ns,
                      Object name)
Returns an IFn associated with the namespace and name.

Parameters:
ns - a String or clojure.lang.Symbol
name - a String or clojure.lang.Symbol
Returns:
a clojure.lang.IFn

read

public static Object read(String s)
Read one object from the String s. Reads data in the edn format.

Parameters:
s - a String
Returns:
an Object, or nil.


Copyright © 2014. All Rights Reserved.