Hi Jochen,

> Do we really? If we really want to support it, we should support its
> use-case, which is a Lexer. Writing an efficient lexer in Groovy would
> be way off with switch expressions, because of the transformation to
> Closure and the overhead it involves.

To be frank, I'm not sure if we really want to support it. I think Groovy
should be groovy, but Groovy has to be keep compatibility with Java...

I think Groovy should be able to do better, and it can transform all
statements to expressions, e.g.

1) switch-case
```
def a = 6
def r = #(
    switch (a) {
         case 6:  yield 'a'
         default: yield 'b'
    }
 )
assert 'a' == r
```

2) if-else
```
def a = 6
def r = #(
    if (a == 6)
         yield 'a'
    else
         yield 'b'
 )
assert 'a' == r
```

3) for
```
def r = #(
    for (int i = 0; i < 2; i++) {
         if (1 == i) yield i
    }
 )
assert 1 == r
```

Cheers,
Daniel.Sun



-----
Apache Groovy committer & PMC member 
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun 

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Reply via email to