Am 27.05.2015 15:16, schrieb Rhangaun .:
Has someone given a thought about adding someting equivalent to Swift's
autoclosure annotation in Groovy ?
http://www.archgrove.co.uk/weblog/2014/06/09/swift-semantics-auto-closing-over-parameters
as I see it you have
def foo(){1}
def bar(a,@autoclosure b){2}
bar(foo(), foo())
which will change the second foo call to lazy evaluation. The expansion
in Groovy would then look similar to this:
bar(foo(),this.&foo()) // plus curry
or
bar(foo()) {foo()}
This can be done only in a static language, or in dynamic language that
does all evaluation lazy by default. In other words, normal Groovy is
not well suited for this.
And then there is of course the question of if I want this. In Groovy
you would declare bar normally as
def bar(a, Closure b)
So to me it is more a way to avoid explicit writing of method closures...
Not sure about the gain from this.
bye blackdrag
--
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/