On Jan 3, 2024, at 23:49, Robert Dodier robert.dodier@gmail.com wrote:
Hi Blake, thanks for your reply.
I actually don't need to convert to ASCII -- what I really want to do is to call a Java method which has a char argument. I got the following error:
CL-USER(19): (jss:new "org.armedbear.lisp.LispCharacter" #\U2502) #<THREAD "interpreter" native {41BFB5BC}>: Debugger invoked on condition of type JAVA-EXCEPTION Java exception 'java.lang.NoSuchMethodException: LispCharacter(java.lang.Character)'.
Do you need to 1) call an arbitrary Java method with a char argument, or 2) just programmatically call the org.armedbear.lisp.LispCharacter constructor to get a Lisp character?
For 1) calling arbitrary Java methods, one should be able to use JSS to do the following:
(#0"charValue" (#"valueOf" 'java.lang.Character #\U2502))
The #0 returns the raw value of the method invocation without attempting to convert through the Lisp/Java FFI.
For 2) why can’t you use CODE-CHAR
(char-code #\U2502) => 9474 (code-char 9474) =>#\│
It appears that the Lisp character #\U2502 has been converted to a Java Character, but that's not acceptable to the org.armedbear.lisp.LispCharacter constructor, which is declared to take a char argument; see line 70 of src/org/armedbear/lisp/LispCharacter.java in the current version (commit bba779e).
Indeed it does change back to a java.lang.Character instance, even when I use the method to return the raw Java type. I cant figure out a way to coerce calling arguments to a primitive char. Maybe I haven't found the right invocation yet, but otherwise we will have to fix the implementation.
Now a complicating factor is that the LispCharacter(char) constructor is declared private -- I don't know if that's the actual problem, and the error message about the argument type is misleading. Are Java private methods, variables, and constructors visible from Lisp?
JSS:NEW should be able to invoke private constructors. That is one of the features which distinguishes it from JAVA:JNEW.