KEMBAR78
Clojure (Clojure API)
clojure.java.api

Class Clojure



  • public class Clojure
    extends java.lang.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 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]"));
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.Object read(java.lang.String s)
      Read one object from the String s.
      static IFn var(java.lang.Object qualifiedName)
      Returns the var associated with qualifiedName.
      static IFn var(java.lang.Object ns, java.lang.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(java.lang.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(java.lang.Object ns,
                              java.lang.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 java.lang.Object read(java.lang.String s)
        Read one object from the String s. Reads data in the edn format.
        Parameters:
        s - a String
        Returns:
        an Object, or nil.