Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123757 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 E2BCA1A009C for ; Sat, 22 Jun 2024 19:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719086215; bh=h6R3p3boQ3OMGJkwy3Fs2peOAajp6cHJGsDdWZYK7WE=; h=References:In-Reply-To:From:Date:Subject:To:From; b=gvqawUSH4aIgj++hR9UV/cBXWna4fV+dGJSBfR2/VGQKFQMcZBoNsUDXw7U1FVt7p ezeJdVyGpJhBAST1QzIW8oBiBBewVnjr44NbJDJu3p9cuSgwVdDXocQndHdzSU4UKh eCPsZ26erTSjv083p2gf+got9yHxjBxe9NorA3952Uj15tnV9uQAo1OMK98pRXM3GI fyEZ5odN2D/nmoCfQ+I/Uqkn7eg1K9tbcNg79y9ZE8cReQXarXwBu+vW+EaQX2Ib4X i8Qx+xDJesohuvG/ope9TlyEX9qoY+TeQ8hecRqgAs9a3C5qDuwl0wd3HdbRj749/f 95JCwCUTDqJIQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4721E1806CD for ; Sat, 22 Jun 2024 19:56:55 +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_MISSING, 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-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (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 19:56:54 +0000 (UTC) Received: by mail-il1-f171.google.com with SMTP id e9e14a558f8ab-376243a112cso11453175ab.3 for ; Sat, 22 Jun 2024 12:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itafroma.com; s=google; t=1719086139; x=1719690939; 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=klEXXKbfivd4/1iB658nNV43jWyDCI++sUveip0kcTw=; b=gHw/KmJdEkMciucsH4MhGAFc0WzKZpgi46ydnsVseFT9WsoBd2J12aYiRNEIYWn9er 3Ixmcl7g62t1VQExOpDoqSaPDMPd6ZGTRZSxPXIVMA3agGVSj2yDJqFpsnNs5au782SR PiK4p5ZcspdFFIbdguwpxZzCGQIx1p3eDe21s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719086139; x=1719690939; 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=klEXXKbfivd4/1iB658nNV43jWyDCI++sUveip0kcTw=; b=r3JEthhWNdu13LFkJFM6U9jWTlKMGLedI/vIOmNNF6LA7QSmi8JtFlxUGwIMTedmvp Q0dZ6fs+ekSM3O0gg7xoN5Y/CIVV8rzh/YTaRu1e4dOUr/BPe+dg3qJAexzJE/E91ZS1 Si3WPEFVMZ79+rZ91TkL6sFtNXKJoLAuSjprCI2jfsoln2VZ+9ln1IOCyvyHdCKUEEkL pLjVoEzMoxZszoJ6zSyShE/t8m+pumb3EJoMkamV+6XF7CkAJ7gIP6xf/o0HU8dc5VpV srC2n0xCnA/vXtWDUf3CoJT/tfc05S4vTMBvYUq/mUpk6kE6DJzcY5P+Q9zM0BYYlG1J p4oA== X-Gm-Message-State: AOJu0YykI4vqqPXbOs1ia8Y7zAhr25Xe+wEfWQo0whP+GxUHf36WO34A 4x4i+vE+xyxQR7P7rKNwIBQQdunThTKEZUGrZhGfAoZPglJMlOXur2Eb5bsRRHNNwOXBjA0KL0W VjYyySIby4KS9JkeT7DxZVVaPwwcvC8FKUMepJcRaQCLqp4dfRQ== X-Google-Smtp-Source: AGHT+IGbZVhoJOY5pqfH3r+ROVediRW0uupq387OWaQ2frGxgiHt+jMTZu1B6RZ5k6JhIw+Sm/A9ZcUY/6TvVsMexb8= X-Received: by 2002:a05:6e02:b4b:b0:375:86bb:2142 with SMTP id e9e14a558f8ab-3763e0607bfmr13339225ab.24.1719086138873; Sat, 22 Jun 2024 12:55:38 -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:55:28 -0700 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: mark@itafroma.com (Mark Trapp) On Sat, Jun 22, 2024 at 10:16=E2=80=AFAM Brandon Jackson wrote: > > > 8. Capturing values out of a pattern and binding them to variables if= matched > > > 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 w= ell as a core feature of every other language that has pattern matching, I = believe. 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. Hi Brandon, Something doesn't sit right with me when an argument is made that something should be in this RFC because it's needed for another, future RFC (in which case, it seems like it should be part of that RFC), but in this particular case, one doesn't need to ever care about ADTs to justify binding being a part of a pattern matching RFC. Without a familiarity of the concept, I think it's very easy to view pattern matching as syntactic sugar for type or shape assertions: in other words, it simply provides another way to ensure type safety. Believe me, I've made the same mistake! Naming things is hard, and "pattern matching" as a name just intuitively feels like it should just be about the checking. But pattern matching's value is in type checking is incidental, and I think a core thing to note from the preamble of the RFC is the following: > In a sense it serves a similar purpose for complex data structures as reg= ular expressions do for strings. Pattern matching's core purpose is to extract data from a matched data structure, and just as regular expressions have limited value without matching groups, pattern matching is similar without binding. I think it would be difficult to think of an implementation of regular expressions without matching groups, and similarly it would be difficult to think of a useful implementation of pattern matching without the ability to extract the data from the matched data structure. Because of this, every language that implements the concept also includes binding. Hope this helps, Mark Trapp