[armedbear-devel] Java callbacks
Hello, 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. Thoughts? Ale
On Tue, Oct 13, 2009 at 11:21 PM, John Pallister <john@synchromesh.com> wrote:
On Tue, Oct 13, 2009 at 9:44 PM, Alessio Stalla <alessiostalla@gmail.com> wrote:
Thoughts?
Sounds pretty good to me, FWIW. Have you frequently found yourself wanting such a thing, or did you just notice the gap in the coverage of the API?
Not frequently. I'm writing a library which in a certain use case needs a factory of Java objects passed by the user (in this case, a Java programmer, not a Lisp programmer). I thought that I could design my own interface to model the factory, but then I thought that I could just pass a Lisp function, and then the idea of a more Java-friendly general callback class (since as I said extending Function involves a bit of boilerplate). At this point the thing is clearly more general than my particular use case, and since Java integration is abcl's main strength, I just thought it could be a nice addition to it. Bye, Alessio
participants (2)
-
Alessio Stalla
-
John Pallister