Skip to content

Commit

Permalink
clojure integration
Browse files Browse the repository at this point in the history
  • Loading branch information
witek committed Feb 22, 2018
1 parent 46c28b2 commit ed3850c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<classpathentry exported="true" kind="lib" path="lib/xmlbeans-2.6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xstream-1.4.8.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jbcrypt-0.3m.jar"/>
<classpathentry exported="true" kind="lib" path="lib/clojure-1.9.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/spec.alpha-0.1.143.jar"/>
<classpathentry exported="true" kind="lib" path="lib/core.specs.alpha-0.1.24.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions download-dependencies.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,6 @@ mavendownload commons-codec commons-codec 1.10

servistodownload asterisk-java-1.0.0.final.jar

mavendownload org/clojure clojure 1.9.0
mavendownload org/clojure spec.alpha 0.1.143
mavendownload org/clojure core.specs.alpha 0.1.24
45 changes: 45 additions & 0 deletions src/main/java/ilarkesto/clojure/Clojure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2011 Witoslaw Koczewsi <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package ilarkesto.clojure;

import java.util.Arrays;

import clojure.lang.IFn;

public class Clojure {

public static void main(String[] args) {
System.out.println(eval("(+ 2 3)"));
System.out.println(eval("(defn doit [] (println \"hello from clojure\") (+ 3 4))\n" + "(doit)"));

IFn myFunction = evalExpectFn("(ns my.stuff) *ns* (defn html [input] (str input))");
System.out.println(myFunction.invoke(Arrays.asList(1, 2, 3, 5, 8, 13)));
}

private static IFn evalExpectFn(String clojureCode) {
return (IFn) eval(clojureCode);
}

public static final IFn loadString = clojure.java.api.Clojure.var("clojure.core", "load-string");

public static Object read(String s) {
return clojure.java.api.Clojure.read(s);
}

public static Object eval(String clojureCode) {
return loadString.invoke(clojureCode);
}

}

0 comments on commit ed3850c

Please sign in to comment.