Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DD11F200D26 for ; Fri, 6 Oct 2017 01:02:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DB6F5160BDA; Thu, 5 Oct 2017 23:02:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2BBDC1609E2 for ; Fri, 6 Oct 2017 01:02:02 +0200 (CEST) Received: (qmail 7534 invoked by uid 500); 5 Oct 2017 23:02:01 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 7524 invoked by uid 99); 5 Oct 2017 23:02:01 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2017 23:02:00 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 38998180915 for ; Thu, 5 Oct 2017 23:02:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.201 X-Spam-Level: X-Spam-Status: No, score=-0.201 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id TtqfL17Pi4QQ for ; Thu, 5 Oct 2017 23:01:59 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 9C03E5FDEA for ; Thu, 5 Oct 2017 23:01:58 +0000 (UTC) Received: from [192.168.1.4] ([77.177.237.18]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M0bo2-1d9vPn0E6Y-00uo6B for ; Fri, 06 Oct 2017 01:01:57 +0200 Subject: Re: New syntax explosion To: dev@groovy.apache.org References: <2BA8478A2FBAFF4FBFDF1724FAD8C09E8C817AFE@C111BKGPMBX48.ERF.thomson.com> From: Jochen Theodorou Message-ID: <960ed1af-4a03-fc96-c40a-1b5976a619c9@gmx.org> Date: Fri, 6 Oct 2017 01:01:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:I8atjxSTplklUTsGVwjiTPnklccFphep9cMixID8LXz9p8Hv7LY RvkhmM8Vu3ZqsIPaINHujS2DOHxMpgClBPKkfs8XtnI408U+wqEjFslU4sHaNO5w+qd1+IC lFaP1dosCOgXUSYd2VJi3nt9JleIF+2+sva8uxJnRHsu0jXZHOHzCRuRM66M6KKB++WNIzq 4C0qiqztiHVDpQGgsFynw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Hb//XefVCfI=:HSDcJrOUktqtpN+bGAoMRy B9+K8dpAyYR0gqvWQaMehwtL1+9AOgYsU+rEP2grWEP4zfbvUrHaRZ88O+MXGkBkyiMY9TK8A rmVnaGRA+GVpl3uUKOcCgYv4y/JhC6hsoSw1DT94TcWyyhkK07RWCTVoPGogsYc90+iVJjfE0 DD8GAZxlNFcrEDYSJ40yT5u9sCxK/4LDg9sCE36uP1q5fqArrNGbHTNvRd+spO7uUPMH8YcIT boyofHWODRr1Ag/yuLXNcoDGcIBQ6Auh5+cZ4k8r6NKpGcl6Buu5BsKUJsayJpKwk/orExHaA 6wjzvoX3hPNCPE6I4uZJvYFzg3HG7YRnqh8UKY0rRUeEeGxzSZzdjs72Wje6AYAfhzgVbrjL9 9fNOVwXZNPyotcZZkiY0Ujn/62AceL5acCtKQO/aRoZ/jP8vwrlj0aYS2tqkALy0h2xOQOzOq JALhLjNAQZffyCce2CjUPKt81qVdpu6+grFPyFdtuNiXXJ3s4AQ3rpjS969KI8SvUCFsTkYn8 swQ4Kkat0M85FuAftAWTV3v2kbWSC1fNALomfJD2/ldLKoRVz4iv5yysi0SeofIDiKB77dvxA l/eB5xsK9L4aPK4wzzwMgS5rMyidKNsHkL5KvOLD70w4IaHfMEaOg5b+O+fPTDDQux+KVEWQ4 SLFT2KaOZy89itsqm6MVWJVzEpckTQ6cRzYKY5MG4WtHv1z+QvMvLwTLE0si+/i3SQOEXmmeV k8y6HcHThG+k5sa5unDgIxvlFIqCYDMg1fC1WZDvOXI+dtXm2Hf+Iay6VMKUDxwD7pqL2xupm qNhlnBgb0bRZYhN626p906ADPDie9QCwfVdt+RnW096yhzWkS8= archived-at: Thu, 05 Oct 2017 23:02:03 -0000 On 05.10.2017 21:23, Andres Almiray wrote: > FYI the switch statement is likely to become an expression in Java.next > (18.3 or 18.9) thus Groovy will have to support it at some point. To give here a bit more fuel see JEP 305 and http://cr.openjdk.java.net/%7Ebriangoetz/amber/ I take from this, that the syntax is most likely not going to be the statement as expression. And in my opinion that does not make sense, just because it can return something does not make it an proper expression right away. After all we have the return statement, and it does return something, but it is no expression and nobody here would think about making it one. In those documents they are even giving up on something like this: switch (someNumber) { case 1: case 2: return "some number"; break; default: return "unexpected number"; } no break anymore, case 1 and case 2 cannot match at the same time. And now you have to have blocks for more than one line: return switch (someNumber) { case 1 || 2 -> "some number" default -> { return "unexpected number" } } And since this is derived from the lambda constructs, it is clear I have a lambda body on the right, thus a return will return from the lambda, not the method I am in and then something like just return "some number" could be even illegal. And since this will mean "abusing" switch-case for very different semantics I donĀ“t really expect this to be the final form, if the cases should support more complex expressions and destructering patterns. And now compare with the Groovy version: return switch (someNumber) { case 1: case 2: return "some number" default: return "unexpected number" } or without the internal returns: return switch (someNumber) { case 1: case 2: "some number" break; default: "unexpected number" } Frankly I am unsure what I really prefer. If we really want to just implement what java has, we have to wait till they finalize the syntax. If we want to go beyond that, we have again to wait. or we get again similar but different versions of syntax and semantic for a large number of cases as we have now with Closure and lambdas. And btw, we should probably mention Scala here. look at their match-case. I think https://www.artima.com/pins1ed/case-classes-and-pattern-matching.html gives here an interesting overview. I am not saying we should do what Scala did here, but compare what is on this page with the documents from Brian. And you will find many many parallels and also maybe where we will go to. Maybe not with Case-classes like in Scala, but if destructering comes, then there will be bigger changes... Anyway I think I start to loop here, so I better stop ;) bye Jochen