Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123709 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5AE031A009C for ; Thu, 20 Jun 2024 20:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718915044; bh=LLPal8YuS7Slnypku7HK6+2pO4knNq+RCnlpF4Yn0ss=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YJrHyUUq6rH1mHT9RRnGLONSpdjou0kVWv5ZaR3Qih1OdgSMk5ycbhfeQMmkFk49g CddmbtAOeL0kTyyoGNMa/i6M5zFUMp9MDXn+/cLFVPl3E77gsXAL/t2jZVZKjIBPDs MFU21cyuHn04PuLp4u1ZGjQh7kkY545PrV9qZGlTm0lKUdNpciqDdaZyr9eFg8BYAf 47Dka7QGaZKRu3zQ2RcWOwtv20XUbhrzLOQSIO3P5daDlJtRghcJIHlKLNFlBMZQZz PIDFy4ZU9uRaggmyxmOfoPsL1uuWI8jnwEL9zq5mQj80VS60vwLeauFrmAS0FKh5gC Avjnjt+or6HJg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 676E21806BD for ; Thu, 20 Jun 2024 20:24:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Jun 2024 20:24:03 +0000 (UTC) Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3629c517da9so1388391f8f.2 for ; Thu, 20 Jun 2024 13:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718914968; x=1719519768; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3f3UwXmsw3BrCFrPe9Jr31215ZjhDBEITVeSC/9IZyQ=; b=ckbzWWjmd8/j4s4eL7Xnog/8VFclcJvNm8qfGkmWCROXwMGbyLdSA1fdwA9YZJR4dB bEkQJb7oTXPoCskCjml1YdaopQxmNRB6hv4Ed8LQNUxxnBeFsakKxViK1Hlz8n6/Q4S/ 6VaRRui3Y+eBcrkTnBxev3/WZ3nHM6Hwf/rplUML2yQ3/j2eL9SDcIa3xbJEdrzjqPkd 2COJCBNvU408NA3vf60PvR48rkaIto9ZUeNtEw+fETpHqU52y6HQN6+zn3nKeuPnkVHW Qm/THMQ6dlsNi/EMZfgPN3xTYxOKqvLq9h2NOlzo9hdee6cs5aSL/wmc6Mq1DImMgrMs r6SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718914968; x=1719519768; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3f3UwXmsw3BrCFrPe9Jr31215ZjhDBEITVeSC/9IZyQ=; b=t9RdU2Y2cEPblKTNHguF55yHgW65OXYCTDLydDi1i+5nQ1+o5OOXAWITNWSexUwNyB fHtILx/HVGke4dvFXUFlzSI3PRvmRjaLdL/E15lNmEQHmlct551shxtA4accaUDfZrjO 0eDouHkR0HH1Get/p+t/jahmfpKjN0EjKC83TdKBuf7oyYIN/K4qXczgdMfTmyW8BL3S AAcr9Ogz55xzDqR2hrCGE9A1UAMwj1pooy4ln6sIJWe3Ql0mJq6sRt7UQzfy76TiEMzm dpSuOtBtfBQTAp+somMSCwDgxN3JvQXyWDUx8MsQyVR2/AE7g3QbWcQQl1qwAV4tz86i tWbA== X-Gm-Message-State: AOJu0YwoVmNUJpEHGDxXv/yezoS/AXoQ2+6Y8mUrddxUg6gJ2TCLpk8y uUlPjkUKlUwmFNPEd0A39mkAlNDylisU9VrYdGd5J48ZmLjf6sjWA/iPU9GT98LhpgCjlTUYD6K UvWQ5x9ue8Vwf3v1RWdcYLwrESuW+PRdu X-Google-Smtp-Source: AGHT+IF+141BFPwZFFv0w5t07ZJ9KGAVkNq67E/fe6fkqKtkpXMS1KNZ79wXdhfY1TTTz+ZslIVWZcLbJ/WZBAy9A00= X-Received: by 2002:a05:600c:20b:b0:422:15a9:8efc with SMTP id 5b1f17b1804b1-42475182645mr67881475e9.22.1718914967699; Thu, 20 Jun 2024 13:22:47 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> In-Reply-To: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> Date: Thu, 20 Jun 2024 22:22:19 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000000c86f4061b581448" From: kjarli@gmail.com (Lynn) --0000000000000c86f4061b581448 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 20, 2024 at 7:41=E2=80=AFPM Larry Garfield wrote: > Hello, peoples. > > Ilija and I have been working on and off on an RFC for pattern matching > since the early work on Enumerations. A number of people have noticed an= d > said they're looking forward to it. > > It's definitely not going to make it into 8.4, but we are looking for > early feedback on scoping the RFC. In short, there's a whole bunch of > possible patterns that could be implemented, and some of them we already > have, but we want to get a sense of what scope the zeitgeist would want i= n > the "initial" RFC, which would be appropriate as secondary votes, and whi= ch > we should explicitly save-for-later. The goal is to not spend time on > particular patterns that will be contentious or not pass, and focus effor= t > on fleshing out and polishing those that do have a decent consensus. (An= d > thereby, we hope, avoiding an RFC failing because enough people dislike o= ne > little part of it.) > > To that end, we're looking for *very high level* feedback on this RFC: > > https://wiki.php.net/rfc/pattern-matching > > By "very high level," I mean, please, do not sweat specific syntax detail= s > right now. That's a distraction. What we're asking right now is "which = of > these patterns should we spend time sweating specific syntax details on i= n > the coming weeks/months?" There will be ample time for detail bikesheddi= ng > later, and we've identified a couple of areas where we know for certain > further syntax development will be needed because we both hate the curren= t > syntax. :-) > > If you want to just read the Overview section for a survey of the possibl= e > patterns and our current recommendations, you likely don't need to read t= he > rest of the RFC at this point. You can if you want, but again, please st= ay > high-level. Our goal at the moment is to get enough feedback to organize > the different options into three groups: > > 1. Part of the RFC. > 2. Secondary votes in the RFC. > 3. Future Scope. > > So we know where to focus our efforts to bring it to a proper discussion. > > Thank you all for your participation. > > -- > Larry Garfield > larry@garfieldtech.com I have been looking forward to this RFC, it's such a quality of life to be able to do all this! In terms of things to focus on, I'd personally be very happy with the property/param guards, "as" and "is ", but I won't say no to anything we can get extra here because it's all really nice to have. I noticed that with array structure patterns the count is omitted when using ... ```php if ($list is [1, 3, ...]) { print "Yes"; } // True. Equivalent to: if (is_array($list) && array_key_exists(0, $list) && $list[0] =3D=3D=3D 1 && array_key_exists(1, $list) && $list[1] =3D=3D=3D 3 ) { print "Yes"; } ``` Wouldn't this need a `count($list) >=3D 2`? I'm not sure if the underlying mechanism does the count check as well, but it seems to me like a guard clause for performance reasons in the PHP variant. Maybe a tangent, what about iterators? "Limited expression pattern" I think this would be very valuable to have, though in the proposal it seems cumbersome to use regardless of syntax. It feels like I'm going to be using the variable binding less often than matching against other variables, what about an "out" equivalent? ```php $result =3D match ($p) is { Point{x: 3, y: 9, $z} =3D> "x is 3, y is 9, z is $z", Point{$x, $y, $z} =3D> "x is $x, y is $y, z is $z", }; // vs $x =3D 3; $y =3D 9; $result =3D match ($p) is { Point{x: 3, y: 9, out $z} =3D> "x is 3, y is 9, z is $z", Point{$x, $y, out $z} =3D> "x is 3, y is 9, z is $z", }; ``` To me this makes it much more readable, just not sure if this is even feasible. This is not meant as bikeshedding the syntax, more of an alternative approach to when to use which. --0000000000000c86f4061b581448 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Jun 20, 2024 at 7:41=E2=80=AF= PM Larry Garfield <larry@garfi= eldtech.com> wrote:
Hello, peoples.

Ilija and I have been working on and off on an RFC for pattern matching sin= ce the early work on Enumerations.=C2=A0 A number of people have noticed an= d said they're looking forward to it.

It's definitely not going to make it into 8.4, but we are looking for e= arly feedback on scoping the RFC.=C2=A0 In short, there's a whole bunch= of possible patterns that could be implemented, and some of them we alread= y have, but we want to get a sense of what scope the zeitgeist would want i= n the "initial" RFC, which would be appropriate as secondary vote= s, and which we should explicitly save-for-later.=C2=A0 The goal is to not = spend time on particular patterns that will be contentious or not pass, and= focus effort on fleshing out and polishing those that do have a decent con= sensus.=C2=A0 (And thereby, we hope, avoiding an RFC failing because enough= people dislike one little part of it.)

To that end, we're looking for *very high level* feedback on this RFC:<= br>
https://wiki.php.net/rfc/pattern-matching

By "very high level," I mean, please, do not sweat specific synta= x details right now.=C2=A0 That's a distraction.=C2=A0 What we're a= sking right now is "which of these patterns should we spend time sweat= ing specific syntax details on in the coming weeks/months?"=C2=A0 Ther= e will be ample time for detail bikeshedding later, and we've identifie= d a couple of areas where we know for certain further syntax development wi= ll be needed because we both hate the current syntax. :-)

If you want to just read the Overview section for a survey of the possible = patterns and our current recommendations, you likely don't need to read= the rest of the RFC at this point.=C2=A0 You can if you want, but again, p= lease stay high-level.=C2=A0 Our goal at the moment is to get enough feedba= ck to organize the different options into three groups:

1. Part of the RFC.
2. Secondary votes in the RFC.
3. Future Scope.

So we know where to focus our efforts to bring it to a proper discussion.
Thank you all for your participation.

--
=C2=A0 Larry Garfield
=C2=A0 larry@ga= rfieldtech.com

I have been looking forw= ard to this RFC, it's such a quality of life to be able to do all this!= In terms of things to focus on, I'd personally be very happy with the = property/param guards, "as" and "is <regex>", but= I won't say no to anything we can get extra here because it's all = really nice to have.

I noticed that with array str= ucture patterns the count is omitted when using ...
```php
if = ($list is [1, 3, ...]) {
=C2=A0 print "Yes";
}
// True.= =C2=A0 Equivalent to:
if (is_array($list)
=C2=A0 =C2=A0 && a= rray_key_exists(0, $list) && $list[0] =3D=3D=3D 1
=C2=A0 =C2=A0= && array_key_exists(1, $list) && $list[1] =3D=3D=3D 3
= =C2=A0 =C2=A0 ) {
=C2=A0 =C2=A0 print "Yes";
}
```
=
Wouldn't this need a `count($list) >=3D 2`? I'm not sure if= the underlying=C2=A0mechanism does the count check as well, but it seems t= o me like a guard clause for performance reasons in the PHP variant. Maybe = a tangent, what about iterators?

"Limited exp= ression pattern"
I think this would be very valuable to have= , though in the proposal it seems cumbersome to use regardless of syntax. I= t feels like I'm going to be using the variable binding less often than= matching against other variables, what about an "out" equivalent= ?

```php
$result =3D match ($p) is {
=C2=A0 = Point{x: 3, y: 9, $z} =3D> "x is 3, y is 9, z is $z",
=C2= =A0 Point{$x, $y, $z} =3D> "x is $x, y is $y, z is $z",
};<= /div>
// vs
$x =3D 3;
$y =3D 9;
$result = =3D match ($p) is {
=C2=A0 Point{x: 3, y: 9, out $z} =3D> "x is = 3, y is 9, z is $z",
=C2=A0 Point{$x, $y, out $z} =3D> "x i= s 3, y is 9, z is $z",
};
```
To me this makes it much= more readable, just not sure if this is even feasible. This is not meant a= s bikeshedding the syntax, more of an alternative approach to when to use w= hich.



--0000000000000c86f4061b581448--