Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109871 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32890 invoked from network); 28 Apr 2020 12:15:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2020 12:15:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C81391804E0 for ; Tue, 28 Apr 2020 03:49:05 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 28 Apr 2020 03:49:05 -0700 (PDT) Received: by mail-io1-f53.google.com with SMTP id k23so7016416ios.5 for ; Tue, 28 Apr 2020 03:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=GytkEBnWkUr1/RUzNk+62Hea14CpPIokJO+ogQB2weg=; b=p/tobFQKl2oTi95jEC3V/JUhpJlkGhc0zxnAXX/xh6uUY1mHKgwmak4YFyxu9eLIzS jF/PfOxbA2j0S1unm4up0PNd1PqGppbOejigh58b8Nstf3rku8DxKTpoifuZcQLtj+ra Oiq/FJDXsas/4Bi2kuON7HT3p4q3cyBFsGnKKTBboY3HMF/fVWwh3si3zfTzY06XwJQS zr6cDk488dLDtsmyQnTIeJmxivQT8wDj6ByBZ6lM8Lf4is5+dbgoKzjcXLqldrbY3EGH cOHLasb+ug2Ssqgdxd5Y6BbEm9IO4ExFJ0WwRvO671QBEuUQbRPPQOqv2looxY0nZJic 03eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=GytkEBnWkUr1/RUzNk+62Hea14CpPIokJO+ogQB2weg=; b=NApnkHiKArckP8bzh28iuoLqH6lFN0W3pz/2Wgu88nm7zMkvf4qRrSrffxmnkYFzUD n319AIKxrGDyDTTO4QUv1oSRfC9x2mZwoyzIYShd0Luhc5anlpsK3dgpU7CV21ROW6uv uX3sEinMoSNf3snowbQqaWyNEl55m8MOSZcu9J2577pTT4z6ShPpunc/W18WYZQadapF 4UIrMZbgHNOY1f5CRT43VecXFtFzHRghJtFl1mPqAsf8YbdPMua8LIwF4hE2OGl1g8AX 5O/AMR7qk5e7lKAMV2mPXvzgo3TLDY28gocJgM72bjMgLJrvf3jUEgGDagD73WIF/khj wa0w== X-Gm-Message-State: AGi0PuZ1kmkB1tKtmS9ZqJ2jUdInlgHk7NsDilsAEzrUuX9U+f5nRVVc xjIbr3v8baqgxYRHz6f5OBg9XZmOgJozDrZwYHD6ThA6 X-Google-Smtp-Source: APiQypLKgRM68iIYpw2KXIajiymUU1DdAPcQVNMSRMuhIirGxQvrIHlzztJ8AOHrj/z0zR954rUEy+HAVdsTRDVMU4U= X-Received: by 2002:a6b:b258:: with SMTP id b85mr25107333iof.141.1588070943072; Tue, 28 Apr 2020 03:49:03 -0700 (PDT) MIME-Version: 1.0 References: <5ea6e4b0.1c69fb81.cf3ee.2bbfSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Tue, 28 Apr 2020 11:48:51 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000070a57805a457943d" Subject: Re: [PHP-DEV] [VOTE] match expression From: rowan.collins@gmail.com (Rowan Tommins) --00000000000070a57805a457943d Content-Type: text/plain; charset="UTF-8" On Tue, 28 Apr 2020 at 11:19, Ilija Tovilo wrote: > > for the control-flow statement, it feels awkward and not in > > keeping with the rest of the language. If they were separate proposals, > the > > statement would probably end up looking very different. > > Can you elaborate? If I made a proposal exclusively for match > statements the syntax would be exactly equivalent. > If we take away the expression part, the proposal would be to replace this switch statement: switch ( $expr ) { case 1: case 2: statement; break; default: statement; break; } With this match statement: match ( $expr ) { 1, 2 => { statement; }, default => { statement; }, } The extra set of {} inside looks a little odd, but is a reasonable way to remove the implicit fallthrough. However, the other changes seem to just be arbitrarily new syntax: * No "case" keyword * => instead of : * commas between statement blocks If the motivation is simply to fix the current switch statement, why not keep the syntax more familiar? match ( $expr ) { case 1, 2: { statement; } default: { statement; } } The colon looks unnecessary next to the opening brace, but if we keep it, the braces could be optional like they are in an if statement: match ( $expr ) { case 1, 2: statement; default: statement; } Note that this wouldn't suffer the problems of accidentally running code that you get with one-line if statements, because the following could simply be a syntax error: match ( $expr ) { case 1, 2: statement; anotherStatement; default: statement; } That syntax doesn't lend itself as well to being used as an expression, but I'm not convinced making one syntax work for both use cases is the right goal given the compromises it requires. Regards, -- Rowan Tommins [IMSoP] --00000000000070a57805a457943d--