On Nov 27, 7:24*pm, Alexander Burger <a...@software-lab.de> wrote:
> Mike Schilling <mscottschill...@hotmail.com> wrote:
> > To begin with, why is the OP using reflection at all? *It's of no value in
> > the code actually posted, which could simply call method the normal way..
>
> Sure, but this is just a prepared, reproducible example.
>
> The actual code is the Java version of PicoLisp. The plain runtime
> system ist at "http://software-lab.de/ersatz.tgz", the full system
> including sources at "http://software-lab.de/picoLisp.tgz".
>
> There is a generic 'java' function which allows to call arbitrary
> constructors and methods, on arbitrary objects. And, this indeed works
> most of the cases, but sometimes (like here for 'JPanel' and 'add') not.
>
> The lisp-level function 'java' accepts four syntax patterns:
>
> * *(java 'obj ['cnt]) -> any
> * * * Converts a Java object back to Lisp data
>
> * *(java 'obj 'msg 'any ..) -> obj
> * * * Invokes a method 'msg' on an object 'obj' with arguments 'any'
>
> * *(java 'cls 'msg 'any ..) -> obj
> * * * Invokes a static method 'msg' in class 'cls' with arguments 'any'
>
> * *(java 'cls 'T 'any ..) -> obj
> * * * Returns a new object of class 'cls' by calling the constructor of
> * * * that class with arguments 'any'.
>
> For example, this works (analog to the posted plain Java example):
>
> * *(setq
> * * * frame (java "javax.swing.JFrame" T "Title")
> * * * panel (java frame "getContentPane")
> * * * area (java "javax.swing.JTextArea" T 10 40) )
>
> * *(java frame "setSize" 300 200)
> * *(java frame "setLocation" 100 100)
>
> * *# ??? (java panel "add" JTextArea)
>
> * *(java frame "setVisible" T)
>
> Just the line with "???" does not, and this is the case which also has
> "???" in the original post.
You can have a look at how ABCL does it. Your java operator is called
jcall in ABCL, and it does perform some dynamic dispatch in the vein
of what javac does for method resolution; though it probably isn't
100% compatible with what the JLS specifies, it's "good enough" for
the cases we encountered so far. Some pointers:
(incomplete) documentation of ABCL's Java FFI:
http://trac.common-lisp.net/armedbear/wiki/JavaFfi
Implementation of jcall and other primitives:
http://trac.common-lisp.net/armedbea...lisp/Java.java
ABCL home page:
http://common-lisp.net/project/armedbear
Cheers,
Alessio