[armedbear-devel] Java callbacks

Alessio Stalla alessiostalla at gmail.com
Tue Oct 13 20:44:40 UTC 2009


I was thinking about the integration of lisp and java with abcl and it
struck me that we don't have an easy way to pass a callback from Java
to Lisp (e.g. a function acting as a factory of objects): one can
extend Function, Primitive or even LispObject and implement the
appropriate execute() method overload; however, one must perform
conversion to/from Lisp objects manually, and while this is a minor
inconvenience, it adds boilerplate code that could be easily avoided.
So I was thinking about adding a Callback class extending Function,
with overloads for execute() taking and returning regular
java.lang.Object instances, and corresponding execute() based on
LispObjects that perform the necessary conversions and call the
Java-friendly versions. Example:

public LispObject execute(LispObject arg0) {
    return JavaObject.getInstance(execute(arg0.javaInstance()));

/** To be overridden by the implementing subclass */
protected Object execute(Object arg0) {
    return error(new WrongNumberOfArgumentsException(this));

Such a class could have convenience factory methods taking Runnables,
Callables and other popular kinds of Java callback objects.



More information about the armedbear-devel mailing list