On Tue, Mar 20, 2018, 5:15 PM MG, <[email protected]> wrote:
> With regards to the Groovy 3.0 Release Notes > (http://groovy-lang.org/releasenotes/groovy-3.0.html) "Nested code > blocks" section: > What about in addition supporting two reserved keywords, "block" and > "eval", as follows: > > void foo() { > block { > // Makes nested code block explicit (without it, the block could > e.g. have a missing if or else construct before it) > // Avoids the need to use semicolon before nested code block to > distinguish code block from a closure > // Otherwise no difference to Java nested code block > } > > // equivalent to: > if(true) { ... } > > > final x = eval { > // Nested code block whose final evaluated statement is its return > value > } > > // semi-equivalent to: > final x = true ? (...;...;...) : null > } > > > The application for these constructs for me lie in cases where one needs > to create a scope with a local variables, but where one would need to > pass a large number of parameters to a helper method that coud be > introduced, or one would really have to try hard to come up with a > meaningful method name (implying that the functionality is too > small/specialized to be moved into a seperate method). > > Thoughts ? > mg > > > >
