From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113078 invoked by alias); 27 Feb 2015 02:25:36 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 113051 invoked by uid 89); 27 Feb 2015 02:25:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 27 Feb 2015 02:25:31 +0000 Received: from [10.9.9.206] (helo=mailfront02.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1YRAcJ-0001gN-TK for kawa@sourceware.org; Fri, 27 Feb 2015 03:25:27 +0100 Received: from 70-36-239-115.dsl.dynamic.fusionbroadband.com ([70.36.239.115] helo=toshie.bothner.com) by mailfront02.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1YRAbz-0006X0-Jx for kawa@sourceware.org; Fri, 27 Feb 2015 03:25:07 +0100 Message-ID: <54EFD57D.9060808@bothner.com> Date: Fri, 27 Feb 2015 02:25:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: kawa@sourceware.org Subject: Re: Support Iterable in for-each References: <52D048D4.2080803@bothner.com> In-Reply-To: <52D048D4.2080803@bothner.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q1/txt/msg00051.txt.bz2 [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/