From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21107 invoked by alias); 27 Feb 2015 20:43:22 -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 21089 invoked by uid 89); 27 Feb 2015 20:43:22 -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 20:43:11 +0000 Received: from [10.9.9.207] (helo=mailfront03.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1YRRka-0006Iw-6v for kawa@sourceware.org; Fri, 27 Feb 2015 21:43:08 +0100 Received: from 70-36-239-115.dsl.dynamic.fusionbroadband.com ([70.36.239.115] helo=toshie.bothner.com) by mailfront03.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) id 1YRRkO-0006x1-Mx for kawa@sourceware.org; Fri, 27 Feb 2015 21:42:56 +0100 Message-ID: <54F0D6CD.20207@bothner.com> Date: Fri, 27 Feb 2015 20:43:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: kawa@sourceware.org Subject: Re: Support Iterable in for-each References: <52D048D4.2080803@bothner.com> <54EFD57D.9060808@bothner.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q1/txt/msg00054.txt.bz2 On 02/27/2015 09:35 AM, Jamison Hope wrote: > On Feb 26, 2015, at 9:25 PM, Per Bothner wrote: >> I've checked in code to generalize map, for-each, and vector-map >> so the sequence arguments can be "generalized sequences": > Very cool. I see that map always returns a list, regardless of the > type(s) of the sequence argument(s). Yes - the alternative seems too complicated. Scala has a complicated framework for picking a result type based on the argument type, but it seems very complicated and fragile. What if you map sqrt over an int[]? Should the result be a double[]? What when there are multiple sequence arguments? Note the rules have to work sanely and consistently both with compile-time typing and run-time-typing. It's a lot easier when the compiler just knows the result type. And as you show there is an easy work-around with constructors and splices. > So if I've got an ArrayList of numbers > #|kawa:1|# (define arraylist (java.util.ArrayList 1 2 3 4 5)) > and I want to produce another ArrayList containing the squares of > those numbers, I can do. > #|kawa:2|# (java.util.ArrayList @(map square arraylist)) > [1, 4, 9, 16, 25] > Which is more idiomatic, (apply type list) or (type @list) ? I'd say the latter. Currently apply isn't well optimized, Though splicing isn't as well optimized as I'd like, it's better than apply. For example calling a varargs method with a splice is complied pretty well. My plan is to have the compiler rewrite: (apply f x y lst) to: (f x y @lst) When that is done they'll have the same performance, Further out, the plan is to allow this syntax: (java.util.ArrayList (square (each arraylist)) ...) This uses the same '...' as in syntax patterns, and 'each' is a magic function inside the context of a '...'. It would also work in patterns: (! [x ...] arraylist) ;; x is 'each' element of arraylist (java.util.ArrayList (* x x) ...) I expect this feature before the next release. > BTW, I had to define a remove() method for CharacterIterator in > gnu/lists/Sequences.java to build with Java 1.7, which doesn't have > these newfangled "default" methods. Oops - fixed. > I also had to add > > to the java-classes target in build.xml. It doesn't seem like it's strictly needed, but I fixed this too. -- --Per Bothner per@bothner.com http://per.bothner.com/