From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: Pattern matching on match-string groups #elisp #question Date: Sat, 27 Feb 2021 11:17:55 +0100 Message-ID: <288FFC66-E3BE-4E5F-AAD5-309A632F8058@acm.org> References: <87v9agxkld.fsf@tcd.ie> <80CE2366-76F4-4548-B956-F16DFCE23E4C@acm.org> <258C930A-B183-4211-9917-0AD96C17A638@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3163"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "Basil L. Contovounesios" , Ag Ibragimov , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 27 11:43:02 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lFx3t-0000iU-SX for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Feb 2021 11:43:01 +0100 Original-Received: from localhost ([::1]:53150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFx3s-0001yu-W6 for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Feb 2021 05:43:01 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFx2Y-0000s8-2q for emacs-devel@gnu.org; Sat, 27 Feb 2021 05:41:38 -0500 Original-Received: from mail1471c50.megamailservers.eu ([91.136.14.71]:47332 helo=mail102c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFx2V-0002sp-9N for emacs-devel@gnu.org; Sat, 27 Feb 2021 05:41:37 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1614421077; bh=XaEAo2OrvuSeWQx1k0Zk/wUoyrdTsWqkH6R48tced+8=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=GSy/2CTqML692Ztzpo2YKCVbe1ABSzMyJl+NaGvlzxHcMCt3WfiUDzROzaca4N+Fq Xi2rnZQW3k/Kd28CdOsGy+k39PdqKlTFUOssS+oTcD21/9DSGqvYBb4S+YNoAwZ4x+ Y7U7mHgGg/DeOPvOK3kGF1tIhZv1X6iNTjgu9tKM= Feedback-ID: mattiase@acm.or Original-Received: from stanniol.lan (c-b952e353.032-75-73746f71.bbcust.telenor.se [83.227.82.185]) (authenticated bits=0) by mail102c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 11RAHtXY008525; Sat, 27 Feb 2021 10:17:57 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.17) X-CTCH-RefID: str=0001.0A742F1A.603A1C55.0019, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=KdGsTjQD c=1 sm=1 tr=0 a=von4qPfY+hyqc0zmWf0tYQ==:117 a=von4qPfY+hyqc0zmWf0tYQ==:17 a=kj9zAlcOel0A:10 a=M51BFTxLslgA:10 a=iRZporoAAAAA:8 a=kXLn112teRQ2F9D6AgAA:9 a=CjuIK1q_8ugA:10 a=NOBgFS-JBQ2l-kSd6-zu:22 X-Origin-Country: SE Received-SPF: softfail client-ip=91.136.14.71; envelope-from=mattiase@acm.org; helo=mail102c50.megamailservers.eu X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265717 Archived-At: 26 feb. 2021 kl. 20.38 skrev Stefan Monnier : > BTW, I was thinking about making the optimization more conservative, = so > it only throws away the actual `if` but keeps the computation of the = test: [...] > and it does fix the `pcase-let` problem with your original code. Given the trouble I think we can defend not respecting side-effects in = something as functional as pcase! > It should macroexpand to something morally equivalent to: >=20 > (cond ((not (stringp STR)) nil) > ((not (string-match "\\(?1:a*\\)" STR)) nil) > ((looking-at "^"") > (let* ((x1464 (match-string 1 STR))) > (let ((FOO x1464)) FOO)))) Oh dear... perhaps we should just go with the intermediate list (or = vector) and suffer the small allocation penalty? (At least we should = treat the case of a single variable specially, since no consing would = then be necessary.) My guess is that a vector may be faster than a list if there are more = than N elements, for some N. Should we use string-match-p when there are no variables bound in the rx = clause? >> Of course a sufficiently optimising compiler would eliminate the = consing! >=20 > Indeed, and it's not a difficult optimization (at least if you can > presume that this data is immutable). Right, although we would need some more serious data-flow infrastructure = first. It would be useful for pattern-matching two or more values at the = same time. >>> It's linked to the special undocumented pcase pattern = `pcase--dontcare` >>> (whose name is not well chosen, suggestions for better names are >>> welcome) >>=20 >> pcase--give-up >=20 > Hmm... probably not much more explanatory than "dontcare". Well, 'dontcare' suggests that anything would do and the value not being = used, like '_', but that's quite misleading. > I was thinking of `pcase--impossible` as well. Yes, that looks acceptable. In any case, it isn't really a user-facing = symbol, is it? Otherwise we'd need crystal-clear semantics (and lose the = double dashes).