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 EEDED200BBD for ; Tue, 8 Nov 2016 14:36:03 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id ED9E2160B0A; Tue, 8 Nov 2016 13:36: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 3FB84160AFA for ; Tue, 8 Nov 2016 14:36:03 +0100 (CET) Received: (qmail 71014 invoked by uid 500); 8 Nov 2016 13:36:02 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 71004 invoked by uid 99); 8 Nov 2016 13:36:02 -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; Tue, 08 Nov 2016 13:36:02 +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 E2F09CA0AE for ; Tue, 8 Nov 2016 13:36:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 5.487 X-Spam-Level: ***** X-Spam-Status: No, score=5.487 tagged_above=-999 required=6.31 tests=[DKIM_ADSP_CUSTOM_MED=0.001, HTML_MESSAGE=2, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_SOFTFAIL=0.972, URIBL_BLOCKED=0.001, URI_HEX=1.313] 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 gme24_DyxUpJ for ; Tue, 8 Nov 2016 13:35:59 +0000 (UTC) Received: from mbob.nabble.com (mbob.nabble.com [162.253.133.15]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 434715F1E5 for ; Tue, 8 Nov 2016 13:35:59 +0000 (UTC) Received: from static.162.255.23.22.macminivault.com (unknown [162.255.23.22]) by mbob.nabble.com (Postfix) with ESMTP id D133C358618C for ; Tue, 8 Nov 2016 05:26:56 -0800 (PST) Date: Tue, 8 Nov 2016 06:35:57 -0700 (MST) From: Krzysztof Kowalczyk To: users@groovy.incubator.apache.org Message-ID: <1478612157163-5736542.post@n5.nabble.com> In-Reply-To: <1475738667698-5735822.post@n5.nabble.com> References: <1475738667698-5735822.post@n5.nabble.com> Subject: Re: Possible to improve tuples MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_29580_1635089918.1478612157175" archived-at: Tue, 08 Nov 2016 13:36:04 -0000 ------=_Part_29580_1635089918.1478612157175 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi Bienlein, I think it could be done with AST, it shouldn't be hard to do it in naive way, but would not be easy to do it right. If you want to go with list as return type then you would need to find every occurence of this type of assignment. So you would need global ast transformations that finds every occurence of Declaration that contains ArgumentList and assignment which resolve to list and rewrite it. Simplistic way would be to replace the whole declaration with declaration for every variable as "Type variable = list[index] as Type" and the type of declared variable. You would need to assign the list to a variable first, otherwise you would call function many times. This would not complain if the code makes no sense. You could check that with more work. Other option would be to use map instead: @Tupledef getTuple(){ if(a) [a:1] else [b:2]} The actual return type can be complex to get in general if there are many flows with different return types. But Assuming there is only one return type and we dealing with simple methods, then you could create an AST transformation that change the return type of this method to some type, let say Tuple_a_int_b_int, or just random name. But then it would used bit differently: def x = getTuple()println x.aprintln x.b I'm just evaluating ast transformations on my own so I am not able to tell how hard it would be in practice.https://dzone.com/articles/groovy-ast-transformations Regards,Krzysztof -- View this message in context: http://groovy.329449.n5.nabble.com/Possible-to-improve-tuples-tp5735822p5736542.html Sent from the Groovy Users mailing list archive at Nabble.com. ------=_Part_29580_1635089918.1478612157175 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hi Bienlein,

I think it could be done with AST, it shouldn't be hard to do it in naive way, but would not be easy to do it right. If you want to go with list as return type then you would need to find every occurence of this type of assignment. So you would need global ast transformations that finds every occurence of Declaration that contains ArgumentList and assignment which resolve to list and rewrite it. Simplistic way would be to replace the whole declaration with declaration for every variable as "Type variable = list[index] as Type" and the type of declared variable. You would need to assign the list to a variable first, otherwise you would call function many times. This would not complain if the code makes no sense. You could check that with more work. Other option would be to use map instead:
@Tuple
def getTuple(){
  if(a) [a:1]
  else [b:2]
}
The actual return type can be complex to get in general if there are many flows with different return types. But Assuming there is only one return type and we dealing with simple methods, then you could create an AST transformation that change the return type of this method to some type, let say Tuple_a_int_b_int, or just random name. But then it would used bit differently:
def x = getTuple()
println x.a
println x.b
I'm just evaluating ast transformations on my own so I am not able to tell how hard it would be in practice. https://dzone.com/articles/groovy-ast-transformations

Regards, Krzysztof

View this message in context: Re: Possible to improve tuples
Sent from the Groovy Users mailing list archive at Nabble.com.
------=_Part_29580_1635089918.1478612157175--