Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109294 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8152 invoked from network); 25 Mar 2020 16:35:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2020 16:35:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 405D21804DD for ; Wed, 25 Mar 2020 08:00:06 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 25 Mar 2020 08:00:05 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 2FE235C025F for ; Wed, 25 Mar 2020 11:00:05 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 25 Mar 2020 11:00:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=O9wJi0p09l8Kw8j8ANiuvkZ7i17M8NHY10Wwe04vU j8=; b=2xZCdPsNpd7Klf3prPMCGu6775CQ+AlrkeWAj9nI+v/qnbIpaUIKD76Xd gzqbU0S1hZaUg7ybgnVTpYSHHZAzFj9MAcRHuHm43VKX4lquicSymyz2FjJk/R9k O012LYN7iaRUAUUuJn6hr5V+HE0EYSU/XC4BIPstC9lGjrwV6kSq8CGmAsx1UFnq XFr8TLwpq8lHl/4C4Y5Of4+zVe5jh9Neoi0G+C6X04iipyNSdmV+rsYFnxMainXk sr5i5ZNHxUcsnS1EdXV2vXmP3xzSHV9nPkwV+P3yApw+DorvU+sXY8RcR7VrOZML 5zPUsExJaSbSsuyG8Yp89xlpl+ENQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehgedggeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuffhomhgrihhnpehhihhvvgdrsghlohhgnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtg hhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id BA12614200A4; Wed, 25 Mar 2020 11:00:04 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-1021-g152deaf-fmstable-20200319v1 Mime-Version: 1.0 Message-ID: <767910ef-d27b-404c-9ad1-037105c69d12@www.fastmail.com> In-Reply-To: <4513B88E-CA5B-4DF2-94C8-242BEE54ADCC@me.com> References: <047092C7-84FB-42AB-8084-7B83F76F55C1@me.com> <4513B88E-CA5B-4DF2-94C8-242BEE54ADCC@me.com> Date: Wed, 25 Mar 2020 09:59:43 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] switch expression From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 25, 2020, at 9:27 AM, Ilija Tovilo wrote: > Hi Micha=C5=82 >=20 > =20 >=20 > I=E2=80=99m sorry, unfortunately I missed your e-mail and RFC. >=20 > Let me know if you=E2=80=99re still working on it and I=E2=80=99ll bac= k off of course. >=20 > =20 >=20 > Regards I like the concept, and it looks like you're both on a similar track. G= ive or take details, I would very much like to see something like it. One possible improvement to either version is allowing an expression on = the left side. That is, rather than doing an equality match, do a boole= an match. That would then allow: $foo =3D switch($bar) { case $bar < 5 =3D> $bar * 3; case $baz < 10 =3D> $bar * 4; default =3D> $bar * 5; }; That would sidestep the need for pattern matching, as you can do anythin= g an expression can do. The obvious caveat of course is figuring out ho= w to reference the variable being switched on, if it's not already a var= iable. My first thought there is to borrow the $$ variable name from Sa= ra's old function composition proposal, but there may be others. There'= s likely other issues to discuss here but allowing expressions on the le= ft would greatly improve the expressiveness of the construct. I'd prefer to not allow multi-line statements on the right, ie, blocks. = That leads to too much potential for long and ugly code, which a constr= uct like this should be avoiding. Limiting it to a single expression ke= eps it compact; if you have more involved logic, then put it in a functi= on and your expression is just... calling that function. Problem solved= . Side note: I did a limited user-space implementation of the same concept= a while back: https://hive.blog/php/@crell/type-matching-in-php But I'd definitely rather see it in the native syntax. --Larry Garfield