Armed Bear Common Lisp (ABCL) - User Documentation

"It's the right to arm bears" Paul Westerberg

Overview

Benefits of using ABCL

Installing ABCL

Hello, world!

ABCL Cons and LispObject classes

Other important ABCL classes

All the classes below are in the org.armedbear.lisp package:

Getting a Lisp package from Java

Getting a Lisp function from Java

Calling a Lisp function from Java

Converting Java objects to Lisp values and vice-versa

Since the user can't be expected to know how to map every Java type to Lisp and vice-versa, there are a couple
of nice methods you can use in all cases:

Calling Java from Lisp

This code sample is by Ville Voutilainen.

Java code

public class Main {
    public int addTwoNumbers(int a, int b) {
        return a + b;
    }
}
See the entire code sample here.

Lisp code

We need to get the

  1. class (Main)
  2. classes of the parameters (int)
  3. method reference (getting that requires the class of our object and the classes of the parameters)

After that we can invoke the function with jcall, giving the method reference, the object and the parameters. The result is a Lisp object (no need to do jobject-lisp-value, unless we invoke the method with jcall-raw).

(defun void-function (param)
  (let* ((class (jclass "Main"))
         (intclass (jclass "int"))
         (method (jmethod class "addTwoNumbers" intclass intclass))
         (result (jcall method param 2 4)))
    (format t "in void-function, result of calling addTwoNumbers(2, 4): ~a~%" result)))
See the entire code sample here.

Sample Code

References


This documentation was written by Paul Reiners (except where otherwise noted). Helpful suggestions and corrections were given by Alessio Stalla and others on the ABCL mailing list. Please email me with any suggestions or corrections.


Creative Commons License
Armed Bear Common Lisp Tutorial by Paul Reiners is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Code samples are released under the GNU General Public License.