From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20095 invoked by alias); 9 May 2014 16:19:02 -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 19975 invoked by uid 89); 9 May 2014 16:19:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 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, 09 May 2014 16:18:58 +0000 Received: from [10.9.9.206] (helo=mailfront02.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1WinVd-0000ym-IJ for kawa@sourceware.org; Fri, 09 May 2014 18:18:53 +0200 Received: from 70-36-239-203.dsl.dynamic.sonic.net ([70.36.239.203] 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 1WinVc-0001d5-3q for kawa@sourceware.org; Fri, 09 May 2014 18:18:52 +0200 Message-ID: <536CFFE6.1080801@bothner.com> Date: Fri, 09 May 2014 16:19:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: kawa@sourceware.org Subject: Splicing lists and vectors into argument lists Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-q2/txt/msg00032.txt.bz2 Please try out this new experimental Kawa feature: The form '@EXPRESSION' (which is reader syntax for ($splice$ EXPRESSION)) can be used in a function application. The EXPRESSION must evaluate to a list or vector (more generally a java.util.List) *or* a native Java array. The effect is that each element becomes a separate argument. For example if lst is a list, then (fun x y @lst) is the same as: (apply fun x y lst) To sum the elements of list/vector/array lst, do: (+ @lst) To concate vectors vec1 and vec2 separated by a single value x, do: [@vec1 x @vec2] Splice notation isn't optimized much so far. If an application contains a splice argument then we just create an array of the elements and invoke the applyN method. This means there is no function-specific optimization. Which also means if inlined compilation behaves differently from run-time application you get the latter behavior. (This can happen when resolving overloaded methods, for example.) The plan is to do some optimization, starting with array/list constructors. Calling varargs methods can also be optimized: If all the splice arguments correspond to a varargs array, then the compiler should generate code to create the varargs array and then emit a regular 'invoke' instruction. Right now Kawa follows Java when handling varargs, in that you can optionally in the final argument pass an explicit array which is treated as a varargs array. This will be deprecated soon, and ultimately disallowed. E.g. the following is currently allowed: (define args (object[] 4 5 6)) (java.lang.String:format "" args) ; DEPRECATED ;; as equivalent to: (java.lang.String:format "" 4 5 6) In the future this will have to be written: (java.lang.String:format "" @args) Note that the syntax (@TYPE ARG ...) is also used for annotations. That usage don't conflict for a number of reasons: - The @TYPE syntax for an annotation is only allowed in function call position, while a slice is *not* allowed in function call position. - The "expression" following @ for an annotation must be a class or type, while for a slice it must be a list/vector/array. - Annotations are only supported in restricted contexts. The old syntax (TYPE:@ VALUE) for coercions still works, but deprecated. Use (->TYPE VALUE) instead. However, there is *some* compatibility breakage, since '@' no longer starts a symbol. Thus for example I had to quote |Q| in syntaxutils.scm. This macro could presumably be replaced by colon notation. Finally: Don't use keyword values in the elements of splice. This will soon stop working, but that is a topic for another email. -- --Per Bothner per@bothner.com http://per.bothner.com/