Skip to content

tailrecursion/javastar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javastar

Write Java inside Clojure:

(require '[tailrecursion.javastar :refer [java*]])

(defn sum-doubles [arr]
  (java* [] double [doubles]
    "double s = 0;
     double[] arr = ~{};
     for(int i = 0; i < arr.length; i++) {
       s += arr[i];
     }
     return s;"
     arr))

(sum-doubles (double-array 10 1.0)) ;=> 10.0

(defn hi-from-java [name]
  (java* [] String [String] "return \"hi \" + ~{} + \"!\";" name))

(hi-from-java "Bob") ;=> "hi Bob!"

(defn add2 [x y]
  (java* [] long [long long] "return ~{} + ~{};" x y))

(add2 1 2) ;=> 3

(java* [clojure.lang.Var clojure.lang.RT]
       Object [String String]
       "Var str = RT.var(\"clojure.core\",\"str\");
        return str.invoke(~{},\" \", ~{}, \"!\");"
       "holy"
       "cow") ;=> "holy cow!"

Requires Java 1.6 JDK or higher.

Dependency Build Status

[tailrecursion/javastar "1.1.6"]

License

Copyright © 2013 Alan Dipert

Distributed under the Eclipse Public License, the same as Clojure.

Releases

No releases published

Packages

No packages published