Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 07FD3200D70 for ; Fri, 22 Dec 2017 03:40:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EE527160C2C; Fri, 22 Dec 2017 02:40:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3D0EC160C2B for ; Fri, 22 Dec 2017 03:40:03 +0100 (CET) Received: (qmail 70885 invoked by uid 500); 22 Dec 2017 02:39:57 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 70875 invoked by uid 99); 22 Dec 2017 02:39:57 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Dec 2017 02:39:57 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 87D1CC4450 for ; Fri, 22 Dec 2017 02:39:56 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.702 X-Spam-Level: X-Spam-Status: No, score=-0.702 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id sJDHnPlvwZ2D for ; Fri, 22 Dec 2017 02:39:54 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 4072A5F2A8 for ; Fri, 22 Dec 2017 02:39:54 +0000 (UTC) Received: from [192.168.1.3] ([77.178.148.100]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MCLx3-1eJef22TmT-00978p for ; Fri, 22 Dec 2017 03:39:53 +0100 Subject: Re: G-String embedded Closure calling bug? To: dev@groovy.apache.org References: <1513894844444-0.post@n5.nabble.com> From: Jochen Theodorou Message-ID: Date: Fri, 22 Dec 2017 03:39:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:pnh1hSaUyOTFJmdcIopYhy5eS+CZxNBt5Bu0dr41xvTV2Er/+fb 5F3IDHQw6MIwTeA4Ow+Gbg4lbzV+VWUk5IkKmaWGzetdEoG9iXuZWX8CJgj/nhjB/hxipu/ 7FU0/h/NPMzYy8QgUlwbTjVlpAUhQGKpVfHz0Wax6txyuQUpiqtFS49jeUXyZhAAXSYhKN1 /QCiYKwsA/TJO/sVdTzdg== X-UI-Out-Filterresults: notjunk:1;V01:K0:URpvX1ggy/w=:Ndl2//JNOpjUjT08FtYF4i EZXvOKvuT91JqSPE6CupFoNNpsha0QAhzWFd3LXjoDIYm0hQpeGuJMOo8HUsINJhKW6fxDhDs G7OphFsXUpK0hrDvEwR1YrBQCq3biXapNpRQuf5NxOO3hTI33tVcQP5KPXfb75eb9I8AWV3hW TQasdN0Q867hMC24SnSkuOgMuV/janEghzpcsObPuTMePiN+jTfHHnO28Tp7b7jtwlxpFlMer 5ynWnMizGCwTgXTBRFswM/6VwhQqg3ZzMvvzEAB5xQ0+q8xg35Q7+Lv2r0x2vdjZYXhC7e6IG KlTmwZIg8dLeicitVITnHmijpbCQ0HmUDERxaMhqkC8kCWl+fx3u1TiKVKhKVe0pqR5Lw8+nI K2rDPBfDwJpMEIg72ZXqi7nOlcna1CfztObdXzZueMLj//9QjgT+O7qWfFQCvoVKGjjfkBmb7 zDUPuZ0or/4ShgpgoqUUTmgE0aBPDPdNdBvciFbUwuG7ir7RnWQOwR24DpQt5/KJwqXcNM2vZ J4/nfdhUEhaNtL0VlCNr2RCXNTIwfDyl0cWpeoPPAx1fEinKWY2bwhxqX3yVevV6reoAneIOs gPa5QTcZdlZXYGV0HbhoRoxUUhOZY03y5lYfWwAtJSqCcNybwxg5djxCsQD+B0eCSqbqCsY2f V0ZZabqZNpltj2jSV8DlJE3vr0+8Nl1DcfSY6Fu6GUj3McpEdwsQflDxwhhBf7qnjH5rj2Y7U 3FWL2Ug57KhaNlalDAviNevqBTig+Krm80bvWzwO2B/uIosNhcxXkceDstT3QDOVTIDreY5Ur Zb14XYz/AO9zP0jgAiL5Fu3B5WKMvQ52qRbbygd8LyJv02YIJJKAo5DaDKnL81vK9ha1B3S archived-at: Fri, 22 Dec 2017 02:40:04 -0000 On 22.12.2017 00:20, Paul King wrote: > I suspect this is intentional but was before my time. Try this also: > > int triggered = 0 > def o1 = { -> triggered++ } > def o2 = { println '*' + it; triggered++ } > > println(o1) // ConsoleScript11$_run_closure1@xxxxxxxx > println(o2) // ConsoleScript11$_run_closure2@yyyyyyyy > > assert triggered == 0 > println("xyzzy$o1") // xyzzy0 > assert triggered == 1 > println("XX${o2}YY${o2(42)}ZZ") // *42\n*XX\nXXYY1ZZ > assert triggered == 3 ah yes... good old times with John Wilson... I think the idea was back then to leverage the Closures for templating engine purposes.. like for example GStringTemplateEngine the whole template in there is basically a Closure and writing is channeld by the writeTo method, that is also used for toString. I really wonder how much this feature is used. If you look at the code you will see, that it does lead to very surprising behaviour, for example toString on Closure and writeTo in GString do not fit very well together and the GString base evaluation may lead to a double evaluation by working on the result of the Closure call. Plus of course the different behaviour for if the closure does or does not take a parameter where we one time work on the result and one time we ignore the result and instead let the Closure itself work things out. Frankly, this is on my list of features to be removed. I have not yet fully investigated the impact of this - and I suspect there will be much more impact here than it looks like on first glance bye Jochen