[ 
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}} 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.
 * 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' // 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

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


> 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.
>  * 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' // 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)

Reply via email to