arrays in kawa Per Bothner 03 Sep 2016 00:40 UTC

I've recently worked on documenting the new Kawa array APIs.
You can view the resulting documentation here:

This is very different from SRFI-122 on the surface, but beneath
it supports more-or-less the same functionality, so it should be
practical to implement SRFI-122 using Kawa arrays.  However, I
though it was better to stay compatible with SRFI-25, and (where
practical) Racket's math/array package.

Kawa does support selectable lower bounds (non-zero origin),
sharing via mapping, general function-defined arrays, and
general function-based transformations.

Kawa doesn't have an explicit "interval" type.  Instead,
various functions take "shape specifiers" of various kinds,
which includes SRFI-25's R*2 arrays (see the "Array shape" section).
(For compatibility with SRFI-25 I stuck with the "shape" name.)

I'm not convinced there is a need for an extensive "interval API",
but it wouldn't be difficult to add convenience functions that
work on shapes and returns shapes (presumably in the SRFI-25 form).

Kawa does need functions to make it easier to change the lower
bound of an array or a shape.

I want to emphasize the general indexing facility, which
supports the functionality of APL-style generalized indexing
- i.e. any index can be an integer, a vector, or a general array.
It supports almost all of the functionality of Racket's slices,
but in a more general and less ad doc form.

Kawa is missing some SRFI-122 convenience functions, such
as array-permute and array-curry.  While these can be implemented
using array-transform or share-array, it would make sense to add
similar functionality builtin.

You can declare that a variable has a specific array type.
For example the specifier array2[double] is the type of
rank-2 arrays of primitive (unboxed) doubles.  The Kawa compiler
can make use of such type specifiers to generate excellent
inline code for array-ref, without object allocation/boxing.

The Kawa array library is still a work in progress.  A goal
is better array type inference and using types for better
code generation.  The generic procedures that take a functions such
as build-array could be optimized a lot.

Kawa's experimental "invoke" branch supports pattern-matching.
Using that will make it easier and nicer to work with index
vectors, for example for build-array.

If you want to try it out, you can get a binary snapshot:
You just need Java 7 or better (JDK 8 recommended).
Unzip the downloaded file and run kawa-NNN/bin/kawa .
	--Per Bothner