[armedbear-devel] Using Java Libraries

Carlos Ungil carlos.ungil at gmail.com
Wed Oct 21 22:01:22 UTC 2009


> Hi folks,
>
> I'm searching for a (more systematic) documentation (or tutorial)
> about how to use Java libraries from ABCL.
>
> I couldn't find anything else except the examples on
> "http://trac.common-lisp.net/armedbear/browser/trunk/abcl/examples/abcl".
>
> Is there any such tutorial (or documentation) at all?
> Any feedback is very much appreciated!
>
> Regards
> Nik

Hello,

you might want to check jfli-abcl.

Jfli, by Rich Hickey (who would later create Clojure), makes it
possible to call Java from LispWorks. It was ported to ABCL by Andras
Simon. You can

I've just noticed you can find a recent (and improved) copy of
jfli-abcl (including sample code) from
http://github.com/avodonosov/abcl-idea/tree/master/src/abclidea/lisp/jfli-abcl

My version of the file has a couple of extra things that might be useful.

1) I had to add a case to infer-box-type to be able to call functions
with java.lang.Float arguments.

(defun infer-box-type (x)
  (cond
   ((null x) nil)
   ((boxed? x) (jobject-class (get-ref x)))
   ((integerp x) integer.type)
   ((typep x 'single-float) float.type)
   ((numberp x) double.type)
   ........

2) I think the following change was done by Alex Mizrahi (I took the
file from abcl-web). I don't know if it's still required.

< 			   `(defclass ,(class-symbol full-class-name)
< 			      ,supers ()))))))))
---
> 			     `(unless (get ,class-sym :ensured) ;no fwd ref'd classes in abcl
> 				    (ensure-java-class ,full-class-name)
> 				    (defclass ,(class-symbol full-class-name)
> 					,supers ())))))))))

I also added a "doto" macro similar to the one in Clojure
(http://clojure.org/java_interop#toc15)

(defmacro doto (object &body body)
  `(let ((object ,object))
     ,@(loop for form in body
	  collect `(,(first form) object ,@(rest form)))
     object))

so I can do things like

(document.add (doto (pdfptable.new 3)
		    (pdfptable.addCell (doto (pdfpcell.new (paragraph.new "header
with colspan 2"))
					     (pdfpcell.setColspan 2)))
		    (pdfptable.addCell "A")
		    (pdfptable.addCell "B")))

Cheers,

Carlos




More information about the armedbear-devel mailing list