From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: pcase bindings in patterns with complicated logic Date: Sat, 20 Jan 2024 22:06:46 -0500 Message-ID: References: <87il3xt38w.fsf@localhost> <875xzwjta2.fsf@posteo.net> <878r4rsyyt.fsf@localhost> <87r0ijj48v.fsf@posteo.net> <871qajsx5z.fsf@localhost> <87le8riyvp.fsf@posteo.net> <87r0ihl8lr.fsf@localhost> <87zfx2943z.fsf@localhost> <87sf2s5fx4.fsf@localhost> Reply-To: rms@gnu.org Content-Type: text/plain; charset=Utf-8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30678"; mail-complaints-to="usenet@ciao.gmane.io" Cc: thievol@posteo.net, emacs-devel@gnu.org To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 21 04:06:56 2024 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 1rROAi-0007mp-Gk for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Jan 2024 04:06:56 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rROAb-0008Eo-Su; Sat, 20 Jan 2024 22:06:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rROAZ-0008Eg-Dz for emacs-devel@gnu.org; Sat, 20 Jan 2024 22:06:47 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rROAY-0000lm-NG; Sat, 20 Jan 2024 22:06:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Date:References:Subject:In-Reply-To:To:From: mime-version; bh=fqtkS4qgSFHYi3qSYyx7SWU9udlsxW5PWasx/XsCfjg=; b=sR3l1u1fVD6r bdQUZtqJpJoENYSolydmRAD4WyeylIv0ue+KJzcCXnJWWJmkx2d9L7Ng7bS23ciizm6JzY4x8W6TE PXDJau3hrQwUHo4hSKUasZQoleKfMhGkjvUblGFzIbafPo+gx1AM5/UAfGu8c9WSnOG+lhUOeBIrw WfPNhKGq4U19MZqdrzwSGrpxfKWMp12HeUTIRzNn4xruwsCdGYXFl4qouP8bG/wDFVtavUK/d8o+M 5DideQlP1UctkJ3aDpEomJ+QBCip9t+8sBAe1uh/eHnucwxJCEKC8cfeBl7He/kGZKpYxq5BKyur3 epzd/vugj7aR3FyPQZFrAg==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rROAY-00024E-Di; Sat, 20 Jan 2024 22:06:46 -0500 In-Reply-To: <87sf2s5fx4.fsf@localhost> (message from Ihor Radchenko on Sat, 20 Jan 2024 12:48:39 +0000) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:315162 Archived-At: [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > (pcase '((foo . 1) (bar . 2) (baz . 3)) > ((and `((foo . 1) . ,_) > (app (mapcar #'cdr) `(,_ ,_ ,c))) > (format "Match: %S" c))) > The above matches `((foo . 1) . ,_) against '((foo . 1) (bar . 2) (baz . 3)) > and then matches `(,_ ,_ ,c) against a different value - '(1 2 3) One of the basic benefits of cond* is that you're not compelled to match all the patterns against the same data object. I am not confident I understand app pattern, but if it does what I now think, the equivalent of (app (mapcar #'cdr) `(,_ ,_ ,c))) would be this: (match* `(,_ ,_ ,c) (mapcar 'car '((foo . 1) (bar . 2) (baz . 3)))) What cond* cannot do is apply `and' to two different match* clauses which test different objects. I could add that capability. I could also add `app', if that is worth adding. Its absence is not a fundamental design issue, just that it dud not seem necessary. That example wan't a solution to a real problem, so I am not convinced this is a real gap in cond*. If I see this sort of situation in a real problem, that will convince me I should do something about this. Thanks for helping me understand this issue. -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org)