Friday, April 08, 2011

Grooooovie Groovy!

''An agile dynamic language for the Java Platform'' a primer [source]

''Groovy AST Transformations by Example'' [source]

Take a groovy program, parse it to get its Abstract Syntax Tree (AST),then visit/transform the AST, and what do you get? ... a different groovy program!

And the same mechanism can even be used to optimize (for example tail recursion):
''Tail recursion is a special case of recursion which can be changed to iteration.
The trick is to wrap our function into an endless loop, save the function args into local temps, replace all usages of the args with temps and replace recursive calls by setting the temps to the recursive call args.
Since Groovy is my favourite language on the JVM it seemed the perfect time and target to give my first shot at AST transformations. AST transformations are @nnotations that will be invoked at compile time to let you analyze and manipulate a programs abstract syntax tree.
'' [source]

BTW: AST transformations are a kind of aspect-oriented programming (see here).

No comments:

Post a Comment