[armedbear-devel] Calling java from lisp

Arnaud Bailly arnaud.oqube at gmail.com
Thu Apr 5 14:34:51 UTC 2012


OK. I can see where my first error lies: jcall parameters are
incorrect. Here is a corrected version:

(defun java-format (fmtstring &rest args)
          (let* ((string-class (jclass "java.lang.String"))
                 (array-of-objs (jclass "[Ljava.lang.Object;"))
                 (method (jmethod string-class "format" string-class
array-of-objs)))
            (jcall method nil fmtstring args)))

But this does not work yet as I do not know how to convert a lisp list
to a java array. IS there any utility function  or should I do it "by
hand" ?

Arnaud

On Thu, Apr 5, 2012 at 4:12 PM, Arnaud Bailly <arnaud.oqube at gmail.com> wrote:
> Hello (again),
> I am trying to invoke java code from lisp code following
> http://common-lisp.net/project/armedbear/doc/abcl-user.html.
> Here is the code I am trying to run:
>
> CL-USER> (defun java-format (fmtstring &rest args)
>           (let* ((string-class (jclass "java.lang.String"))
>                  (array-of-objs (jclass "[Ljava.lang.Object;"))
>                  (method (jmethod string-class "format" string-class
> array-of-objs)))
>             (jcall method fmtstring args)))
>
> JAVA-FORMAT
>
> And here is what I got when I try to run it:
>
>> (java-format "" "%d %08.d %s" 1 2 3)
>
> Wrong number of arguments for public static java.lang.String
> java.lang.String.format(java.lang.String,java.lang.Object[]): expected
> 2, got 1
>   [Condition of type PROGRAM-ERROR]
>
> Restarts:
>  0: [RETRY] Retry SLIME REPL evaluation request.
>  1: [*ABORT] Return to SLIME's top level.
>  2: [ABORT] Abort thread.
>
> Backtrace:
>  0: (#<FUNCTION {53C470B}> #<PROGRAM-ERROR {76F2D004}> #<FUNCTION {53C470B}>)
>  1: (APPLY #<FUNCTION {53C470B}> (#<PROGRAM-ERROR {76F2D004}>
> #<FUNCTION {53C470B}>))
>  2: (SYSTEM::RUN-HOOK SYSTEM::*INVOKE-DEBUGGER-HOOK* #<PROGRAM-ERROR
> {76F2D004}> #<FUNCTION {53C470B}>)
>  3: (INVOKE-DEBUGGER #<PROGRAM-ERROR {76F2D004}>)
>  4: org.armedbear.lisp.Lisp.error(Lisp.java:381)
>  5: org.armedbear.lisp.Java.jcall(Java.java:880)
>  6: org.armedbear.lisp.Java$pf_jcall.execute(Java.java:755)
>  7: org.armedbear.lisp.Primitive.execute(Primitive.java:135)
>  8: (JCALL #<java.lang.reflect.Method public static java.lang.String
> j.... {451CF2D}> "" ("%d %08.d %s" 1 2 3))
>  9: (JAVA-FORMAT "" "%d %08.d %s" 1 2 3)
>  10: (SYSTEM::%EVAL (JAVA-FORMAT "" "%d %08.d %s" 1 2 3))
>  11: (EVAL (JAVA-FORMAT "" "%d %08.d %s" 1 2 3))
>  --more--
>
> What am I doing wrong ?
>
> Arnaud




More information about the armedbear-devel mailing list