我正在将Clojure生成的映射传递到Java中,该映射最终将用于JTable。使用map函数会创建一个惰性序列,即使使用doall,也无法实现到{}的序列。 Clojure:
(defn test-lz-seq []
(let [myvec [[1 2 nil][3 4 nil][ 5 6 nil][ 7 8 nil]]
myvec2 (doall (map #(if (nil? (nth % 2)) (assoc % 2 "NA")) myvec))
colnames ["VarA" "VarB" "VarC"] ]
(into {} (java.util.HashMap.
{":colnames" colnames
":data" myvec2} ))))
(println (test-lz-seq))
在代表看来很好:
lnrocks.core> {:data ([1 2 NA] [3 4 NA] [5 6 NA] [7 8 NA]), :colnames [VarA VarB VarC]}
Java代码:
import clojure.java.api.Clojure;
import clojure.lang.IFn;
import clojure.lang.PersistentVector;
.
.
.
public class DialogMainFrame extends JFrame {
private PersistentVector colnames;
private PersistentVector data;
private IFn require = Clojure.var("clojure.core", "require");
.
.
.
System.out.println("==========test code===========");
System.out.println("");
IFn testLzSeq = Clojure.var("lnrocks.core", "test-lz-seq");
Map<String, PersistentVector> hm = (Map)testLzSeq.invoke();
System.out.println(hm.get(":data"));
System.out.println(hm.get(":colnames"));
System.out.println("");
System.out.println("===================================");
在控制台上:
==========test code===========
clojure.lang.LazySeq@e1781
["VarA" "VarB" "VarC"]
===================================
如何在Java中实现矢量?