This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
checked in vector re-write
- From: Per Bothner <per at bothner dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Fri, 31 Jul 2015 23:15:54 -0700
- Subject: checked in vector re-write
- Authentication-results: sourceware.org; auth=none
I just checked in a major re-write of the underlying code for
vectors, strings, and uniform vectors.
The basic idea is to efficiently support vector-indexes, as in APL:
For example:
#|kawa:1|# (! vec1 (vector 'A 'B 'C 'D 'E 'F))
#|kawa:2|# (vec1 [3 5 2])
#(D F C)
The range [2 <: 6] is (roughly) the same as [2 3 4 5]:
#|kawa:3|# (vec1 [2 <: 6])
#(C D E F)
(Th '<:' is a keyword; the '<' is a mnemonic for the
the set of integers '<' the end value 6. You can also use <=:.)
A range is different from a vector integer in that you can use
a range as the index in the LHS of a set!:
#|kawa:4|# (set! (vec1 [2 <: 4]) #(a b c d e))
#|kawa:5|# vec1
#(A B a b c d e E F)
Notice how the number of replaced elements can be different
then the(! str1 number of elements in the replacement value.
I.e. you can do insertion and deletion this way.
The vector automatically converts to a "gap vector".
This also works for strings:
#|kawa:7|# (! str1 (string-copy "ABCDEF"))
#|kawa:8|# (set! (str1 [2 <: 5]) "98")
AB98F
The internal data structures have changed a lot but I won't go into details here.
It's worth mentining that the changes enable better type inference, and better
support of vectors of primitive types (uniform vectors) without object allocation.
These changes aren't as polished and optimized as I would like, but I needed to check
them in so I can focus on something else (for the JVM languages summit, where
I'll be giving a workshop).
--
--Per Bothner
per@bothner.com http://per.bothner.com/