groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject Re: [GEP] Switch expressions syntax from Java 11 or 12 (perhaps)
Date Thu, 01 Mar 2018 19:56:27 GMT
You mean http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html ?

On 01.03.2018 18:34, Cédric Champeau wrote:
> You have to be aware that this java syntax prepares the way for 
> pattern matching. I think we need to wait and see before doing it.
>
> Le 1 mars 2018 17:45, "Paolo Di Tommaso" <paolo.ditommaso@gmail.com 
> <mailto:paolo.ditommaso@gmail.com>> a écrit :
>
>     I agree that groovy should continue to be compatible with java
>     syntax as long as possible.
>
>
>     Cheers,
>     Paolo
>
>
>     On Thu, Mar 1, 2018 at 5:28 PM, Guillaume Laforge
>     <glaforge@gmail.com <mailto:glaforge@gmail.com>> wrote:
>
>         1) Very useful :-)
>         2) I think we should continue the compatibility with Java,
>         like we're doing for Groovy 3, and add that syntax when it's
>         finalized.
>         3) It's too early to think about the implementation, let's
>         wait till the syntax is crystalized first!
>
>         But yeah, I like the idea of supporting it.
>         (and we could potentially support it before the Java version
>         containing it is released)
>
>         Guillaume
>
>
>         On Thu, Mar 1, 2018 at 4:39 PM, Jesper Steen Møller
>         <jesper@selskabet.org <mailto:jesper@selskabet.org>> wrote:
>
>             Hi list
>
>             Java 11 (or perhaps 12) might see a new functionality
>             known as switch expressions
>             (https://bugs.openjdk.java.net/browse/JDK-8192963
>             <https://bugs.openjdk.java.net/browse/JDK-8192963>).
>
>             While the current Groovy implicit return functionality
>             works with the switch statement as-is, the
>             switch/expression/ is a more general construct, basically
>             it is to the conditional operator (a ? b : c) what the
>             switch /statement/ is to if/then/else-if/else. An example:
>
>             |int numLetters = switch (day) { case MONDAY, FRIDAY,
>             SUNDAY -> 6; case TUESDAY -> 7; case THURSDAY, SATURDAY ->
>             8; case WEDNESDAY -> 9; };|
>
>             with
>
>             |case LABEL -> expression;|
>
>             essentially sugar for
>
>             |case LABEL: break expression;|
>
>             As I see it: It could add utility to the Groovy language,
>             and adopting it would keep up the the Java-compatibility
>             gap, which I think is a valuable gateway-drug to
>             discovering the joys of Groovy. The "break <expression>
>             syntax isn't pretty, but the arrows look fine and incur no
>             syntax compatibility problem, as far as I can see.
>
>             Now, this being Groovy, the cases should surely support
>             the extended "isCase"-support, as described so well here:
>             http://mrhaki.blogspot.dk/2009/08/groovy-goodness-switch-statement.html
>             <http://mrhaki.blogspot.dk/2009/08/groovy-goodness-switch-statement.html>
>
>             So, three questions remain:
>             1) Useful or not?
>             2) This Java compatibility - is it still a thing? I
>             remember a similar proposal a little while back, but this
>             would align better with Java.
>             3) This could be implemented using existing AST's if we
>             /_really_/ want to, but it would be clumsy. This AST
>             transformer compatibility - is it still a thing?
>
>             -Jesper
>
>
>
>
>
>
>         -- 
>         Guillaume Laforge
>         Apache Groovy committer & PMC Vice-President
>         Developer Advocate @ Google Cloud Platform
>
>         Blog: http://glaforge.appspot.com/ <http://glaforge.appspot.com/>
>         Social: @glaforge <http://twitter.com/glaforge> / Google+
>         <https://plus.google.com/u/0/114130972232398734985/posts>
>
>


Mime
View raw message