Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123752 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 9EA191A009C for ; Sat, 22 Jun 2024 17:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719076565; bh=WPMovDXUvylzXSWHIHEX26N3GMd+znwKZP2DJLOnzWg=; h=References:In-Reply-To:From:Date:Subject:To:From; b=TDGXxR7uzXBqlW40kSZEViJeSb6StDVyUNdakIb1XvkZMaqFoLuPScelQwheVw1qR cy4RMVp5wZH2q3IV8x11Rth4LZfz8OGl+A9MEi7gJB5aNsDkQMbcZwBLhQIfZ6E30J ueWcEPvvCecT6pFZTnX/z5QboIp9uwQptFc1v1z8Im8VLZ9CBiBWnRZJpSiuT3OCpo NNPVAMsefJWrSk7Q5gCyfiYQUU5lVRbwm9XTjmINWVmC3UtzwXgKT4f6qCcFYqyXhf qLaIAaWFF7XkufCPwbEVmlAEO6+PQ6ShfhN6Ui0zZb4X0VjQ0jd4ohGauc3pL+PHP5 oIhuW4S530pfg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 99A42180874 for ; Sat, 22 Jun 2024 17:16: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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,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-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (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 ; Sat, 22 Jun 2024 17:16:01 +0000 (UTC) Received: by mail-vs1-f52.google.com with SMTP id ada2fe7eead31-48f5295f81cso40158137.2 for ; Sat, 22 Jun 2024 10:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719076486; x=1719681286; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7/hLtVkU5+9HEFeIxkX25hFk3hd4fL7rq906VZhBE7o=; b=ClZkT7NB+Byujyv05kdBJy1xqFh9tEQ2znDiQx7Qzj3hy6Q81GRR73Dfk0YzHO1OmV piX/Odw8RUZt1MtBMIthQ0TyE3vVO06F/ANES/AImmWQy4BX7IAoEGiYbd+yfJvsxAvw dgqVLW7q7juISe/R5/61+Nfm81i2mhSHyzKuXP60e5VAvzZSWSSMj4xuyrrOuKxwaMeg 8n67lYZSvH2aVdFNlHDt3gMtfNrR8sHLSF4sspcvaNQeK66uXcR7ihItjFu3UYXN1fFd M8Ul0OOz7a0l1BA4qWIsnAYbVtSs9RRMA2EM+Z3SwFqX48NZq+tgXMOkEidqm7FylLsj 6eIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719076486; x=1719681286; h=content-transfer-encoding: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=7/hLtVkU5+9HEFeIxkX25hFk3hd4fL7rq906VZhBE7o=; b=BdTdFajxcjmgnbpvoK73ODyw6Mrg9YWcEfobzTqzU400CDR62LSixuXnFzFU7JEEx2 7GRzbGqOTkGW6yaRpSgXwwJKGPxFKSCrf1m53GSBMbgZR95xgEDKZLc5oCCafYENwuhr YIOM9oqhUsSGJPINg99bayd9Ha8hGPCejC/A0cNuuPd9sKLhumegWyU76D+wEIDvunPY gyLo0aS5hvljcxzjTX4lTGdanyEXzwVR1gSQchn39ARJGZZkBaS97WlVXjA+D+phW3GM OT0J53CD+TZeuBxsSeDEkLgv6ksLAohReuw0kRcJOayhkRI0NWtsZyq3TrK3fbwmhyEN 0uzw== X-Gm-Message-State: AOJu0YwWGKQ6/ZTo4sN0JQdtM1Ixp9EzNHSephh+iv3Swg7sG9olsmm2 /4IBgMPjERx9v5umheYSjKtJ24iaNXJWn4kZfjJEQ56zfiM1453RdX5V1UUL3B5xzpJBEC1a0o5 apDbUNdSaMGDy+0D5ibCbTFYxgSaZVukI X-Google-Smtp-Source: AGHT+IFJ4Wj6cbqFEuO+ORjp+S7hwBHG3FSyVWDHf8WFzUE3ahbcGyS4t7tf5BvoXeGvnpM+ixnHNjzqVzoo2O/cugs= X-Received: by 2002:a67:eb02:0:b0:48f:44fe:734 with SMTP id ada2fe7eead31-48f52b9d88amr601934137.27.1719076485677; Sat, 22 Jun 2024 10:14:45 -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: Date: Sat, 22 Jun 2024 12:14:35 -0500 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: brandonja991@gmail.com (Brandon Jackson) On Fri, Jun 21, 2024 at 1:22=E2=80=AFPM Larry Garfield wrote: > > To give more context, as noted, this is a stepping stone toward ADTs. An= ything that is on the "hot path" for ADT support I would consider mandatory= , so trying to split it up will just take more time and effort. That inclu= des the object pattern and match support, and the object pattern realistica= lly necessitates literals. Variable binding would also be almost mandatory= for ADTs. I'm very reluctant to push off anything in that hot path, as ev= ery RFC has additional overhead, and I'm all volunteer time. :-) I get that, and thank you for any free time you both spend here to help php move forward. I don't mean to imply that some things don't belong here. However, it does seem like some pieces will need more fleshing out than others. It would be nice if those that require less fleshing could proceed without being delayed (or completely rejected) by those that need more. But it sounds like this is meant to be an all or nothing type thing. > As noted above, I don't think it's feasible to postpone this one. It's a= lso pretty simple, and wouldn't have any conflict with enums unless we went= all in on the guards options, which we most likely will not in the initial= version. That's good to hear. This is one of my top requested items in this rfc and would love to see it sooner than later. > As noted, this is on the ADT hot path so postponing it is problematic. E= specially holding it on type aliases, which have been discussed for longer = than this RFC has been around (nearly 4 years) and yet no actual proposal h= as ever been put forward. It's unwise to wait for such a feature, especial= ly when most likely implementations would dovetail well with patterns anywa= y. I should clarify I'm not suggesting to postpone based on this hypothetical feature. Maybe it wasn't a good one, but I'm just throwing out some potential curve balls that could be brought up during discussion. This is one of the items that seems to need a bit more fleshing out than others, and might potentially lead to further delay or an outright rejection and missing out on some good pieces of this rfc. > To clarify here, these all come as a set. Array shapes aren't their own = "thing", they just fall out naturally from array patterns. So it's not pos= sible for associative patterns to conflict with array shapes, as they are l= iterally the same thing. :-) I'd have to check with Ilija but I don't beli= eve there's much internal difference between list and associative patterns.= This one isn't on the ADT hot path, so it could be postponed > > I see no way for associative array patterns/shapes to conflict with gener= ics at all. Thanks for the clarification. I was looking at the example given in the overview trying to figure out the boundaries between array structure patterns, array shape patterns, and nested patterns. It sounds like it can be summarized to nested patterns with the option to add or omit `...` determining if unexpected key/values are allowed. Also again, just throwing out hypothetical curve balls that could delay or halt other good parts. At this point I don't actually expect generics to ever be a thing. > > 8. Capturing values out of a pattern and binding them to variables if m= atched > > Ok I think that's stepping a bit far out of scope. Maybe `is` should > > simply check and not have any side effects. > > As above, this is core functionality of pattern matching for ADTs, as wel= l as a core feature of every other language that has pattern matching, I be= lieve. It's not out of scope, it's core scope. Ok, it just seems like a rift between expectations and reality. When looking at things like this, if it is not actually something that's new to me, I like to try to put myself in the shoes of someone who it would be new to. Why? Because there are things that you can assume a syntax does, and there are things you would only know a syntax does by reading the docs (if it's not buried too deeply and you can find it). I would never have assumed that there was a pattern to be appended to `$foo is Bar` that would automatically assign one of its properties to another variable if there was a match. But I guess that comes from ignorance as I haven't had the luxury of familiarizing myself with a language that does this. So if it is a common thing then I will chalk it up to a bad assumption of mine. > > 9. match .. is > > Nice shorthand to have but i'd rather not see short hands forced in as > > an all or nothing type thing as was done with property hooks. I'd also > > argue that maybe short hands should not be added until a feature has > > been around for at least one release and is generally accepted. That > > way we're not using up syntaxes and limiting the ability to add other > > syntax features without breaking backwards compatibility. Keep in mind > > that the `is` functionality alone allows this (or at least it should) > > and a shorter version may or may not be desired. > > ```php > > match(true) { > > $var is Foo =3D> 'foo', > > ... > > } > > ``` > > This is also core scope of pattern matching in most languages. It's not = just a shorthand, it's a direct enhancement. I didn't mean to downplay the usefulness of this. I do think it would be incredibly useful, and would most definitely use it. To me a short hand is always a direct enhancement. So when I say something is a shorthand I'm not downplaying its significance at all. Although convenient and will allow us to skip ahead in the timeline, I just think shorthands should come after a feature, not at the same time.