[armedbear-cvs] r13102 - trunk/abcl/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sat Dec 25 11:03:53 UTC 2010


Author: ehuelsmann
Date: Sat Dec 25 06:03:50 2010
New Revision: 13102

Log:
Add more type-conversion helpers to java.lisp.

Modified:
   trunk/abcl/src/org/armedbear/lisp/java.lisp

Modified: trunk/abcl/src/org/armedbear/lisp/java.lisp
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/java.lisp	(original)
+++ trunk/abcl/src/org/armedbear/lisp/java.lisp	Sat Dec 25 06:03:50 2010
@@ -219,6 +219,26 @@
 	    i (1+ i)))
     jarray))
 
+(defun list-from-jarray (jarray)
+  "Returns a list with the elements of `jarray`."
+  (loop for i from 0 below (jarray-length jarray)
+        collect (jarray-ref jarray i)))
+
+(defun vector-from-jarray (jarray)
+  "Returns a vector with the elements of `jarray`."
+  (loop with vec = (make-array (jarray-length jarray))
+        for i from 0 below (jarray-length jarray)
+        do (setf (aref vec i) (jarray-ref jarray i))
+        finally (return vec)))
+
+(defun list-from-jenumeration (jenumeration)
+  "Returns a list with the elements returned by successive `nextElement`
+calls on the java.util.Enumeration `jenumeration`."
+  (loop while (jcall jenumeration
+                     (jmethod "java.util.Enumeration" "hasMoreElements"))
+        collect (jcall jenumeration
+                       (jmethod "java.util.Enumeration" "nextElement"))))
+
 (defun jclass-constructors (class)
   "Returns a vector of constructors for CLASS"
   (jcall (jmethod "java.lang.Class" "getConstructors") (jclass class)))




More information about the armedbear-cvs mailing list