[ https://issues.apache.org/jira/browse/GROOVY-10090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17345604#comment-17345604 ]
Daniel Sun commented on GROOVY-10090: ------------------------------------- Let's recall the previous proposal of "switch expression": [http://groovy.329449.n5.nabble.com/VOTE-Support-switch-expression-in-the-next-version-tp5762208.html] I undertood your worries about transforming statements to expression via closure: [http://groovy.329449.n5.nabble.com/VOTE-Support-switch-expression-in-the-next-version-tp5762208p5762209.html] So this proposal is to address your above worries. > Support `BlockExpression` to treat statement as expression > ---------------------------------------------------------- > > Key: GROOVY-10090 > URL: https://issues.apache.org/jira/browse/GROOVY-10090 > Project: Groovy > Issue Type: Improvement > Reporter: Daniel Sun > Priority: Major > > We need unify expression and statement by introduing {{BlockExpression}} to > support new features. {{BlockExpression}} creates a new variable scope and > allows {{yield}} to produce the final result, thus statement could be used > where expression appears, e.g. > * GROOVY-9272 could leverage the power of this improvement to treat > statement as expression. > * {{def v = if (pass) 'Yes' else 'No'}} > * > {code:groovy} > def v = while(cnt < 3) { > if (pass) yield 'Yes' // produce the value for BlockExpression (Note: > default value is null) > cnt++ > } > {code} > *Note:* we do not introduce any new syntax for {{BlockExpression}} but just > introduce a new AST node -- This message was sent by Atlassian Jira (v8.3.4#803005)