Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109595 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60238 invoked from network); 12 Apr 2020 15:35:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Apr 2020 15:35:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 587681804B7 for ; Sun, 12 Apr 2020 07:04:52 -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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 ; Sun, 12 Apr 2020 07:04:51 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id v5so7637606wrp.12 for ; Sun, 12 Apr 2020 07:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=RaFzFRs1an3ijEWZ+FdoiTN1P93hHykWdKaWtweAR4w=; b=YqNtgTGSYBwYvZMGHElolNDpsogXe79ExUyLaB1pobncNkXjVyOf6ep5HgQ9eE2hxt cHXrYJADu038Vr3NGoavduo5d3lvy+PqHcktO9znoele4iljLa04XQhEcrlL+qGcqHkv d6azwBmtNPH2JSfX2B1il1nbHlEoYepRT4tejyFU8ZEE6DCfjbnOYow/G3oYAkCGFk7/ KANSeAWXCboAHy6p3+jUpJWVFJtTG+Cr5R6U0p132AajUOnMrAzeTzYBvgFSDCUGTIhv P9C6p2y3LUVU16oSbKMF3ezo159cJqPNlUdKRNz5gvP79UligZIySWpwxKnQYe7S1gbm XIyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=RaFzFRs1an3ijEWZ+FdoiTN1P93hHykWdKaWtweAR4w=; b=Xup9Kxbp23rHNvryPlicX8Zxxrs+difYhAdrlFi3zOqLw/uQHFhh6jWwwZsWxTybAR qbm5gWCF4F/MQwlcatUzh04TzqlbXioaIJU8blUFzahDILwz/9D+Axixag6UNMsFfZ6M /YFUCpPgAKaU68ZU4aTVT7o2Lq5ZbobsikA26Ux6n6wHbRXCpSfmOK0yOWDoo5QROWC2 jsD/OawZckSD+KZHg8tFWBmDIhT+uh2OIF18Nam6B2SrDjZQBhLv8M2WKyRJWlI1c4zd 4HYoNcLC7VytjGH9IZ+uyOcbtiXggyS43vcxVWawzNSOcOvV2anFJ5IydQZZyndjlt4h Hehw== X-Gm-Message-State: AGi0PuYo7Q5jySexTZsvBrD1m+yjAqaP2ve90iZgDVogJVsNhbCKstwy SuZJVT2m7xJZ9bYOqT15YlW684Qg X-Google-Smtp-Source: APiQypK1uCvGVgK5k4aE2p558aVmsBVgADQ5yIUT/xaLzmz782J2uSrgxPCL/cm7EACpM3P1NKEs+A== X-Received: by 2002:adf:f5d0:: with SMTP id k16mr14277592wrp.227.1586700259636; Sun, 12 Apr 2020 07:04:19 -0700 (PDT) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id p10sm10681179wrm.6.2020.04.12.07.04.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 12 Apr 2020 07:04:18 -0700 (PDT) Date: Sun, 12 Apr 2020 15:04:15 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: rowan.collins@gmail.com (Rowan Tommins) On 12 April 2020 01:16:04 BST, Ilija Tovilo wr= ote: >Hi internals > >I'd like to announce the match expression RFC that replaces the switch >expression RFC I announced a few weeks ago=2E >New: https://wiki=2Ephp=2Enet/rfc/match_expression >Old: https://wiki=2Ephp=2Enet/rfc/switch_expression Hi Ilija, Thanks for continuing to work on this, I think the new syntax feels much m= ore natural when introduced with a new keyword=2E > Additionally, match arms can now contain statement lists >which allows you to use the match expression anywhere the switch >statement would have been used previously=2E I quite strongly disagree with this part, however=2E I don't think it's ne= cessary for the new keyword to be a replacement for every switch statement,= any more than switch replaces every if statement or vice versa, and doing = so adds a lot of complexity to the proposal=2E In languages where expression blocks with an implicit return are a standar= d feature, the combination works naturally, but without that we have to add= a bunch of special rules: - Can match arms contain other flow control, such as "return" or "continue= "? What if we later want to give those special meaning? - Can I mix a bare value and a block as arms of the same match, or does th= e whole construct need to be in either "expression form" or "statement form= "? Will this restriction be easy to explain to users? - Can I omit the trailing semicolon even in "expression form", i=2Ee=2E if= my branches have no braces around, as long as I don't use the result? What= will the error message look like if I get this rule wrong? I also think the use of =3D> and , feels natural when pairing an input to = an output, but odd when pairing a test to a block of imperative code=2E In = the "expression form" (no braces, right hand side is an expression evaluate= d if the branch matches), it matches array syntax (right hand side is an ex= pression immediately evaluated as a value) and short closure syntax (right = hand side is an expression evaluated when function is executed)=2E=20 In the "statement form", its closest relative would be if-elseif-else, but= only if we wrote those like this: if ($score=3D=3D10) =3D> { echo "Congratulations"; }, elseif ($score=3D=3D9) =3D> { echo "Nearly there"; }, else =3D> { echo "Keep trying"; } Switch statements are different again, but their ancestor is not if blocks= but goto labels, which explains both the syntax and the fall-through behav= iour: goto "case_$score" else "default"; // imaginary dynamic goto becomes "swit= ch ($score)" case_10: echo"Congratulations"; goto end; // becomes "break" case_9: echo "Nearly there"; goto end; default: echo "Keep trying"; goto end; end: // becomes closing brace of switch block The inability to nest ternary ?: without parentheses makes the single expr= ession form particularly useful in PHP, so I'd love to see the RFC focus on= that=2E We can always add statement blocks in later, either as a special case as c= urrently proposed, or because we're adding them elsewhere, and perhaps with= a way to return a value rather a requirement not to use it=2E Regards, --=20 Rowan Tommins [IMSoP]