groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krzysztof Kowalczyk <>
Subject Re: Possible to improve tuples
Date Tue, 08 Nov 2016 13:35:57 GMT
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
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


View this message in context:
Sent from the Groovy Users mailing list archive at
View raw message