[armedbear-devel] How to create a byte[] from a Lisp vector? (was Re: MAKE-IMMEDIATE-OBJECT and JOBJECT-LISP-VALUE conceptual problem)

Theam Yong Chew senatorzergling at gmail.com
Mon Jun 20 06:59:29 UTC 2011


On 14-Jun-2011 10:49 PM, "Mark Evenson" <evenson at panix.com> wrote:
>
> On 6/11/11 09:06 , Alan Ruttenberg wrote:
>>
>> I've always disliked make-immediate-object. Really it serves the
>> purpose of disambiguating a few overloaded values in lisp. I'd like to
>> deprecate it in favor of specific constants for java-true, java-false
>> and null-pointer (the latter is already available as function).
>
>
> Unless anyone speaks up against this, I will make this change to the Java API.
>
>> It seems dangerous to assume that one can get some java array as the
>> underlying object below a lisp array, what with all the hair that lisp
>> arrays can have.  Better to allocate your buffer with (jnew-array
>> "byte" 8192) and not get into this game. Or have a documented policy
>> of how java objects correspond to lisp objects and promise to support
>> it forever.
>
>
> I agree that we probably shouldn't go down the path of exposing the
>"internal" byte array here.
>
> But I still couldn't find a way to covert a Lisp array of en masse
> to a Java byte[] structure.
>
> One can't construct a byte from a Lisp integer with JAVA:JNEW
>
> CL-USER> (jnew "byte" 0)
>
> fails with #<JAVA-EXCEPTION java.lang.NoSuchMethodException: byte(java.lang.Integer) {39397F0A}>.
>
> Same for
>
> CL-USER> (jnew "java.lang.Byte" 0)
>
> for the same reason.
>
> One can use the Byte(string) constructor
>
> CL-USER> (jnew "java.lang.Byte" "0")
>
> but that seems kludgy in the extreme.  Does anybody have a way to
> create a JAVA-OBJECT containing a byte?  Did I miss something basic?

Yeah, I've forgotten and "worked around" this a few times. I think I
have always converged on (jcall-raw "byteValue" 23) for getting single
byte values.

> And JNEW-ARRAY-FROM-ARRAY on a Lisp vectors of

I have been filling in the array content element by element, after
getting individual byte values as above.

Yong




More information about the armedbear-devel mailing list