I’m new to Groovy and I’m trying to write a mini DSL for some specific task.
For this purpose I’ve been trying to solve a problem like this below:
I’d like to print (and/or return) 5 by calling this code (without using parantheses):
give me 5
I expected that a definition like this below would work:
def give = {clos -> return clos}
def me = {clos -> println clos; return clos}
but actually it doesn’t. Could you please help me how to define “give” and “me” in order to return the value 5 with the expression “give me 5” where me must be a closure, give could be also metaClass, property etc.
Thanks in advance!
Iv
Groovy 1.8+ takes
and the parser effectively tries to do:
So, if you write your code like this, it works:
prints: