forked from hogi/ilarkesto
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |