[armedbear-devel] Lisp->Java object conversion

Alessio Stalla alessiostalla at gmail.com
Thu Jun 25 20:06:51 UTC 2009


ABCL has a built-in way of converting values from Java to Lisp:
JavaObject.getInstance(x, true), which covers the most common cases.

The contrary AFAIK is not as well-defined: conversion from Lisp to
Java is done in ad-hoc ways all over the place. This is not optimal,
especially for someone using abcl embedded into Java - someone who
might not know the rules and conventions used in abcl.

I believe the method LispObject.javaInstance(Class) could be used to
provide such a conversion facility. Currently it has not very clear
semantics: the one in LispObject does a type check to ensure "this" is
an instance of the class passed as parameter, however there are
overrides in subclasses which skip the check and happily return a
value in all cases, ignoring the parameter.

I propose the following unified semantics: x.javaInstance(c) returns a
value (x itself, or some other object) that is guaranteed to be of
class c (*) and to represent a value "similar" to x, for some meaning
of "similar". If such a value cannot be produced, a type error is
signaled. Examples:

LispObject.javaInstance(Boolean.{class|TYPE}) ==> true if this != NIL,
false otherwise
LispObject.javaInstance(anythingelse) ==> this if (this instanceof
anythingelse), error otherwise (like it does now)

Nil.javaInstance(Boolean.{class|TYPE}) ==> false
Nil.javaInstance(anything else) ==> null

AbstractString.javaInstance(CharSequence and subclasses) ==> the string
AbstractString.javaInstance(anything else) ==> error

...etc (numbers, what else?) ...

I.e. in general

x = y.javaInstance(c);
JavaObject.getInstance(x, true).equals(y) ==> true

and

x = JavaObject.getInstance(y, true);
x.javaInstance(y.getClass()).equals(y) ==> true

What do you think?

Bye,
Ale

---------------------
(*) or better, assignable to a variable of type c - this includes null
while the former doesn't.




More information about the armedbear-devel mailing list