this post was submitted on 18 Oct 2023
1 points (100.0% liked)

Lisp

53 readers
3 users here now

founded 1 year ago
MODERATORS
 

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 ?

you are viewing a single comment's thread
view the rest of the comments
[–] aartaka@alien.top 1 points 1 year 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.