groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krzysztof Kowalczyk <kowalczyk.krzysz...@gmail.com>
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
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.
Mime
View raw message