I want to call the square root of 9 from Math:

I tried the following, but it does not work:


(defun main
    (format t "~a~%"
        (JAVA:JCALL (JAVA:JMETHOD "java.lang.Math" "sqrt" 9.0))))
(main)


Can someone provide a working “.lisp” file which calls the java sqrt function from 9 and prints the result 3 for the abcl implementation ?

  • lispm@alien.topB
    link
    fedilink
    arrow-up
    1
    ·
    11 months ago
    CL-USER> (java:jstatic "sqrt" "java.lang.Math" 17.0d0)
    4.123105625617661d0
    
    • aartaka@alien.topB
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

      To add more context to this response: Java has this notion of static methods that belong to classes, compared to the regular methods that belong/act on instances. So ABCL’s jmethod is to call a method using an instance, while jstatic is to call a static method using a class. Math.sqrt happens to be a static method of Math class, so use jstatic. Once this static/regular distinction is cleared up, ABCL interface becomes quite usable.