groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <>
Subject Groov 3.0 - nested code blocks - block/eval
Date Wed, 21 Mar 2018 00:15:21 GMT
With regards to the Groovy 3.0 Release Notes 
( "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 

   // 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 ?

View raw message