Copy elements between a Java primitive array and a Lisp array of matching type.
lw-ji
primitive-array-to-lisp-array p-array &key start end target-start target-end lisp-array => l-result
lisp-array-to-primitive-array l-array &key start end target-start target-end primitive-array => p-result
p-array⇩ |
A Java array of primitive type. |
Bounding index designators. | |
Bounding index designators. | |
lisp-array⇩ |
A Lisp array of an acceptable type, or nil . |
l-array⇩ |
A Lisp array of an acceptable type. |
primitive-array⇩ |
A Java array of primitive type, or nil . |
l-result |
lisp-array or a new Lisp array. |
p-result |
primitive-array or a new primitive array. |
The function primitive-array-to-lisp-array
takes a Java array p-array of primitive type and copies elements from it to a Lisp array of matching type. The target lisp-array is created by default, but can also be supplied as an argument.
The function lisp-array-to-primitive-array
takes a Lisp array l-array of an acceptable Lisp type and copies elements from it to a Java array of matching type. The target primitive-array is created by default, but can also be supplied as an argument.
start and end are bounding index designators for the source p-array or l-array, specifying the range to copy.
target-start and target-end are used only if the target is supplied (by lisp-array or primitive-array). They specify the start and end for copying in the target. The actual number of elements copied is the minimum of the lengths specified for the source and for the target.
If the target (lisp-array or primitive-array) is not supplied, these functions create an array of the correct type and the copy length, and copy into it.
The Lisp array that is passed to lisp-array-to-primitive-array
must be of one of the types listed below, and when the target array is supplied, its type must match the type of the source array according to the table below, except that cl:base-char array (cl:simple-base-string) is acceptable when the Java side is byte
.
Java primitive type | Keyword (result of java-array-element-type) | Lisp type (result of cl:array-element-type) |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
| |
|
|
|
|
|
|
For boolean
, 1 is true
and 0 is false
.
For a large number of elements, these functions are much faster than jvref. If the primitive data is needed for passing to or from foreign functions, use get-primitive-array-region and set-primitive-array-region instead. These functions work only on arrays with one dimension with primitive element type. For non-primitive arrays of one dimension you can use map-java-object-array.
get-primitive-array-region
set-primitive-array-region
map-java-object-array
jvref
jaref
15.4 Working with Java arrays
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:46