Re: Unwrapping Java Character to char

Robert Dodier <[email protected]> Fri, 5 Jan 2024 13:01:03 -0800
Newsgroups gmane.editors.j.devel
Message-ID <CAAsY_sTtrmYAvY-TkS_vZeQZjEjbrkksgqsCg1WU4J-F=ANKnw__11364.7939798952$1704488525$gmane$org@mail.gmail.com>
On Thu, Jan 4, 2024 at 3:11=E2=80=AFAM Mark Evenson <[email protected]> wro=
te:

> > 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.

JSS:NEW doesn't appear to be able to call the private constructor of
LispCharacter -- at least, when I change it to public, then it
succeeds.

With private constructor:

CL-USER(3): #<THREAD "interpreter" native {6B89AFA7}>: Debugger
invoked on condition of type JAVA-EXCEPTION
  Java exception 'java.lang.NoSuchMethodException:
LispCharacter(java.lang.Character)'.

With public constructor:

CL-USER(3): (jss:new "org.armedbear.lisp.LispCharacter" (code-char #x2502))
#\=E2=94=82

The patch is just to make the constructor public -- I didn't change
the argument type; so I guess ABCL was able to see that the
LispCharacter(char) constructor is appropriate, and wedge the
java.lang.Character into a char as needed.

At this point I think the direction I was trying to go (to define new
named characters to be recognized by the reader) is not going to work,
because I can't, without modifying LispCharacter, create a
LispCharacter instance.

Thanks to everyone for their help,

Robert

PS. Here's the patch:

$ git stash show --patch
diff --git a/src/org/armedbear/lisp/LispCharacter.java
b/src/org/armedbear/lisp/LispCharacter.java
index ef9a32c..4219d7e 100644
--- a/src/org/armedbear/lisp/LispCharacter.java
+++ b/src/org/armedbear/lisp/LispCharacter.java
@@ -67,7 +67,7 @@ public final class LispCharacter extends LispObject
   }

   // This needs to be public for the compiler.
-  private LispCharacter(char c)
+  public LispCharacter(char c)
   {
     this.value =3D c;
   }