This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: APL-style array indexing in Kawa - a sketch
- From: Per Bothner <per at bothner dot com>
- To: kawa at sourceware dot org
- Date: Mon, 17 Aug 2015 21:11:51 -0700
- Subject: Re: APL-style array indexing in Kawa - a sketch
- Authentication-results: sourceware.org; auth=none
- References: <55CD4B6A dot 8010606 at bothner dot com> <4E24D268-9062-465B-BF2B-966806394A39 at theptrgroup dot com> <55D2648B dot 2040203 at bothner dot com> <112A4F9C-EF11-4386-B0DC-BA93C01A9CA0 at theptrgroup dot com>
On 08/17/2015 08:37 PM, Jamison Hope wrote:
On Aug 17, 2015, at 6:47 PM, Per Bothner <per@bothner.com> wrote:
We could define [<:] as a supported syntax (see $bracket-list$ in syntax.scm).
It would be relative easy to define 0 as the default lower bound, but that
doesn't quite do what you want. We could define [<;] as a special magic value
that gets coerced to a specific range depending on context.
Hmm can we pick something that won't confuse paredit mode?
I'm not familiar with paredit - but why would [<:] confuse it?
(array-map (lambda (x) (* 2 x)) ARR) => a new array where each element
is doubled in value.
(array-map + ARR1 ARR2) => a new array representing the elementwise sum
of the elements of ARR1 and ARR2.
(I'm imagining that the array-map call wouldn't allocate a new data
buffer, but would just close over the supplied function and array(s),
lazily applying the function to array elements as needed.)
"Lazily" is confusing here. I think array-map should eager, in the
same way vector-map is. What it should do:
(1) Figure out the shape of the result. (The same as the argument, if
a single argument; otherwise they may be "broadcast" in the Racket sense.)
(2) Allocate an Object[] buffer for the result whose length is the
element-count of the shape.
(3) Iterate of the shape (which is the same as iterating over the buffer);
extract the corresponding argument array value using the same (or broadcast)
indexes; call the function.
http://docs.racket-lang.org/math/array_pointwise.html
The Racket array functions is another place to look for inspiration.
--
--Per Bothner
per@bothner.com http://per.bothner.com/