You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2021/05/15 20:45:00 UTC

[jira] [Updated] (GROOVY-10090) Support `BlockExpression` to treat statement as expression

     [ https://issues.apache.org/jira/browse/GROOVY-10090?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Sun updated GROOVY-10090:
--------------------------------
    Description: 
We need unify expression and statement by introduing {{BlockExpression}} to support new features. {{BlockExpression}} reuses the existing 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.
 * Pattern matching could be supported easily, e.g. {{v instanceof Map map}}
 * {{def v = if (pass) 'Yes' else 'No'}}
 * 
{code:groovy}
def v = while(cnt++ < 3) {
   if (pass) yield 'Yes' 
}
{code}

*Note:* we do not introduce any new syntax for {{BlockExpression}} but just introduce a new AST node

  was:
We need unify expression and statement by introduing {{BlockExpression}} to support new features. {{BlockExpression}} reuses the existing 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.
 * Pattern matching could be supported easily, e.g. {{v instanceof Map map}}
 * {{def v = if (pass) 'Yes' else 'No'}}
 * 
{code:groovy}
def v = while(cnt++ < 3) {
   if (pass) yield 'Yes' 
}
{code}


> 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}} reuses the existing 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.
>  * Pattern matching could be supported easily, e.g. {{v instanceof Map map}}
>  * {{def v = if (pass) 'Yes' else 'No'}}
>  * 
> {code:groovy}
> def v = while(cnt++ < 3) {
>    if (pass) yield 'Yes' 
> }
> {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)