[armedbear-devel] Calling java from lisp

Arnaud Bailly arnaud.oqube at gmail.com
Thu Apr 5 14:12:37 UTC 2012


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