This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support Iterable in for-each


[This is a follow-up to a discussion from January 2014.]

I've checked in code to generalize map, for-each, and vector-map
so the sequence arguments can be "generalized sequences":
* any java Iterable, which includes Scheme lists, vectors, uniform
  vectors, and any java.util.List;
* any primitive array;
* and any CharSequence, including java.lang.String and Scheme strings.

vector-for-each is generalized to any java.util.List, using the
get and size methods.  (I.e it assumes the List is RandomAccess.)
Thus it performs poorly on Scheme lists. (Perhaps we should compile
in a cast to RandomAccess to guard against quadratic behavior on Scheme lists.)

Note that a CharSequence is considered a sequence of Unicode scalar values
(a surrogate pair is converted to a single character).  OTOH a native
Java char array is considered a sequence of 16-bit char values.  I think
it makes most sense this way.

If the sequence type is known as compile-time then the Kawa compiler
well generate custom code for that sequence type (see the scanner-for
procedure and the ScanHelper class in compile_map.scm).  Otherwise
it will use an Iterator, selecting the Iterator kind at run-time (see the
static getIterator method in gnu/lists/Sequences.java).

Regardless, if the mapped-over procedure is a lambda it will
get inlined.

The splice operator @ now also handles strings:
  (string #\X @"abc" #\Y) ==> "XabcY"
(However, this has not been optimized as well as I'd like yet.)
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]