Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123807 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 16FF01ADA76 for ; Tue, 25 Jun 2024 07:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719301228; bh=LvmH9GVKhaDRbYNfXB25bqS6Q+r78wOtmNOmkejd91E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=miLaiE9i6/WLFROLplYUao2Ji1h30EZnpREFx0sPrRbrletkBmTW7Wmr3/4aDfmGC QfTUf2GfXZxKd2Tk9MPhD5OPEBdkjuRsqsjUPyekFYD7ZuqSUCwnmzAPBZWXSrHSWp lw6RJUqyh+dVd1KTn08bFBhyyd7bRWrPalupPw4RRcfWeeAEG4NFE0pB3rv1CUNvMs 7n5g42mHOFkfD+706NeK6biXaBX9OY4BmRXMUrt/QH/IuR0BfMeiS26l1u9mjkzV+o hiQWrNDCgLmtjtR5FHREpfg5Ii/I+dLNqx9Y+VnrejJf4zZu/UpmdR0LIoBqD5vmqr rRmTpNfwFdInw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D55D1808C5 for ; Tue, 25 Jun 2024 07:40:26 +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, 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-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 ; Tue, 25 Jun 2024 07:40:23 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2ec595d0acbso28106091fa.1 for ; Tue, 25 Jun 2024 00:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719301145; x=1719905945; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HmFq7ueoR7cduhIXidJNMsmP59ry2GKNx0RYi4TV70Q=; b=HA6iZ8LAtsjdmeb3efspfjImrnLbfV+4mlr+hZkj7hlcdH6qUHFU0EKj6mToWYjtYA qwjZY6GEIzfNWo6W6/JPqFhzmCI40KCso0OiAoR6r3GH04Iy3xl7qwhJwOLOd+CqSZpS WTfB2o9PP7idXqKjigVJK8uFuCTKRemZzwsOBavTwKYBq8LXvx5pwvv1tAX7zOKSNIM0 y1v/j9MinRmTEdpU38GJv5TAEHYrIpaY31PwPtJYLOeD7biJua5xCW+2ZgRjZYqP4PNk BphMzer9KnTJaURtjVgrzS+MvWf4cOR3HOUe7ckjHG+gr22DdC8hZM35jDcHr+hdmD9t E44A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719301145; x=1719905945; h=content-transfer-encoding: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=HmFq7ueoR7cduhIXidJNMsmP59ry2GKNx0RYi4TV70Q=; b=YxmpJZwu5QrY2dgt4UOaZ76qHH9ZAsMNoFFI+dWccfolnVcmYACTWS+GUMGdfuecWU RTHLketvxSRsAyltf8OdZjNZbSuW8gbDTVjqhp2TdqS/cn7VyIvaXvGLS3/zky5UA4st tAVveNY9QB2h6zNGTikU763HM39uo6aFqf75/5em+YIAYPGw1Ih74S6uT5gCFSBx98es 9GRNd/Njd35nrB2IRRqooaG74nLu69JpnXUlKA/pjPwKww5oBBhr5HsWrPOqb91n6NcP 0Up53sglJ/ALBWdGpI+WOQ4OQtdach5N3gVGWNCxFtXzBQMVEmffdmg1IAQUCjuP61Jr gKTg== X-Gm-Message-State: AOJu0YzSFreEq8DTOCtPO0uu2Ft0+Wo7WO9Gbjws4BIsOTlIdKMZdQvl fcFpvUT/lUIe8IIdEa3FGsJRgXfAC05F9GtgqUp0iZiWwWJJWgM4g4m+Wm043wO/gftfJFkBHEC HriIvfrHd6ISG1ST+yCSpU+MA9YHvwbc3aEw= X-Google-Smtp-Source: AGHT+IFeJ2m6BMjLJn2Mw1qCGNRxTjw2YRaEdam5Z9ra/d3SDLhqXStXaWA7yfSjjEaDSxw+crvVLsSANUpJfqX8ekU= X-Received: by 2002:a2e:918a:0:b0:2ec:4086:ea66 with SMTP id 38308e7fff4ca-2ec5b2fc27bmr56425201fa.4.1719301145235; Tue, 25 Jun 2024 00:39:05 -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: Tue, 25 Jun 2024 09:38:52 +0200 Message-ID: Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Tue, Jun 25, 2024 at 2:48=E2=80=AFAM Larry Garfield wrote: > > On Thu, Jun 20, 2024, at 5:38 PM, Larry Garfield wrote: > > > To that end, we're looking for *very high level* feedback on this RFC: > > > > https://wiki.php.net/rfc/pattern-matching > > Hi folks. Thank you to those who have offered feedback so far. Based on= the discussion, here's what we're thinking of doing (still subject to chan= ge, of course): > > * We're going to move `as` to future-scope. There's enough weirdness aro= und it that is independent of pattern matching itself that it will likely r= equire its own discussion and RFC, and may or may not involve full pattern = support. > > * Similarly, we're going to hold off on the weak-mode flag. It sounds li= ke the language needs to do more to fix the definition of "weak mode" befor= e it's really viable. :-( On the plus side, if the type system itself ever= adds support for a "coercion permitted" flag, patterns should inherit that= naturally, I think. > > * Array-application will also be pushed to future-scope. Again, there's = enough type-system tie in here that is tangential to patterns that we'll pi= ck that fight later. > > * Ilija and I have discussed regex patterns a bit further, and it sounds = like they=E2=80=99re going to be rather complicated to implement. Even ass= uming we agree on the syntax for it, it would be a substantial amount of co= de to support. (It=E2=80=99s not like types or literals or range where we = can just drop something pre-existing into a new function.) So we=E2=80=99r= e going to hold off on this one for now, though it does seem like a high-pr= iority follow-up for the future. (Which doesn=E2=80=99t have to be us!) > > So let's not discuss the above items further at this point. > > * I'm going to do some additional research into other languages to see ho= w they handle binding vs using variables from scope, and what syntax marker= s they use and where. Once we have a better sense of what is out there and= is known to work, we can make a more informed plan for what we should do i= n PHP. (Whether using a variable from scope in the pattern is part of the = initial RFC is still an open question, but we do need to design it alongsid= e the capture part to ensure they don't conflict.) Stay tuned on this fron= t. > > * We've removed the dedicated wildcard pattern, as it's equivalent to `mi= xed`. If there's interest, we're open to having a secondary vote to bring = it back as a short-hand pattern. It's trivial to implement and we don't ha= ve strong feelings either way. > > * There's not been much discussion of range patterns. Anyone want to wei= gh in on those? > > * The placement of `is` on `match()` is still an open question. > > * No one has really weighed in on nested patterns for captured variables.= Any thoughts there? > > * I=E2=80=99ve seen a suggestion for capturing the =E2=80=9Crest=E2=80=9D= of an array when using =E2=80=A6 That=E2=80=99s an interesting idea, and = we=E2=80=99ll explore it, though it looks like it may have some interesting= implications that push it to future scope. It feels like a nice-to-have. > > Thanks all. > > --Larry Garfield This morning, while thinking about "new Pattern($pattern)," it occurred to me: why not create an OOP extension of patterns? It wouldn't need an RFC or language changes and would allow the development of patterns to the point where adding it to the core language may be a no-brainer. You (and other users of it) would have a pretty good idea of which patterns are actually important and useful due to actually using them. It's probably the "long way around" but at that point, you'd basically just be pulling in the extension and discussing syntax as the behavior would be well-defined and battle-tested. Robert Landers Software Engineer Utrecht NL