On Wed, 19 Nov 2003, Peter Graves wrote:
> Correct me if I'm wrong, but I think what you're saying here is that if
> you try to do something like
>
> (jcall method instance nil)
>
> and the method in question wants a Boolean for the NIL argument, it's
> not going to work, since JCALL is going to do NIL.javaInstance(), which
> will end up invoking LispObject.javaInstance(), which will signal a
> type error.
>
> Right? (I haven't actually tried this, but that's what it looks like
> would happen.)
Right, but I wanted a little less than this. Just thought that it'd be
nice if something like
(jcall method instance (jfield "java.lang.Boolean" "FALSE" :unwrap nil))
worked. (The imaginary :unwrap is included because jfield by default
will call makeLispObject and so returns NIL.) This is not as ambitious
(and is much easier to implement!) as what you write, though I guess that
that would've been my next wish :-)
>
> I think what you need for this is jlinker's MAKE-IMMEDIATE-OBJECT:
>
> http://www.franz.com/support/documentation/6.2/doc/pages/operators/ja=
> vatools.jlinker/make-immediate-object.htm
>
> Then, in theory, you could do
>
> (jcall method instance (make-immediate-object nil :boolean))
>
> and the Java method would get the Boolean it was hoping for.
Oh, I wasn't aware of MAKE-IMMEDIATE-OBJECT, thanks! But even now I'm
a little uncertain about it:
CL-USER(299): (jnew (jconstructor "java.lang.Boolean" "boolean") (make-immediate-object t :type :boolean))
Error: #<JLINKER-ERROR :JAVA-ERROR - java.lang.IllegalArgumentException: argument type mismatch @
#x71ecd182>
[condition type: JLINKER-ERROR]
or, even worse:
CL-USER(302): (jnew (jconstructor "java.lang.Boolean" "boolean") (make-immediate-object nil :type :boolean))
Error: #<JLINKER-ERROR :JAVA-ERROR - java.lang.NullPointerException @ #x71f266fa>
[condition type: JLINKER-ERROR]
The latter looks like a jlinker bug to me, but the first is more
like a sign of my not quite getting it :-(
>
> In principle, MAKE-IMMEDIATE-OBJECT seems like it would be pretty
> straightforward to implement:
>
> public LispObject execute(LispObject[] args)
> {
> LispObject arg =3D args[0];
> LispObject type =3D args[1];
> if (type =3D=3D Keyword.BOOLEAN) {
> if (arg =3D=3D NIL)
> return new JavaObject(Boolean.TRUE);
> else
> return new JavaObject(Boolean.FALSE);
> }
> }
>
> etc. (glossing over a number of picky details).
>
> I think we could start with a small subset of the combinatorial
> explosion advertised in the table on the aforementioned web page and
> add more combinations as we go along.
I agree (perhaps we can get by without
(make-immediate-object 12.3 :type :string)
for a while :-)). But even if we have MAKE-IMMEDIATE-OBJECT, I think it'd
be useful, though not strictly necessary, to allow jcall, etc. to
return JavaObjects, so one can get away with
(jcall ... (jcall ...))
and needn't write
(jcall ... (make-immediate-object (jcall ...) :type :boolean))
>
> Or am I missing the point here?
Not at all!
Andras
|