From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: pcase bindings in patterns with complicated logic Date: Sun, 21 Jan 2024 14:06:42 +0000 Message-ID: <87edeag4r1.fsf@localhost> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9002"; mail-complaints-to="usenet@ciao.gmane.io" Cc: thievol@posteo.net, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 21 15:04:08 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 1rRYQi-00025U-8O for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Jan 2024 15:04:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRYQ7-0007Eo-Dl; Sun, 21 Jan 2024 09:03:31 -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 1rRYQ6-0007EI-0k for emacs-devel@gnu.org; Sun, 21 Jan 2024 09:03:30 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRYQ3-0007tu-B7 for emacs-devel@gnu.org; Sun, 21 Jan 2024 09:03:29 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 5B20F240101 for ; Sun, 21 Jan 2024 15:03:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705845805; bh=wfUC64cyo91BWKzuWNY9c7bSDoVAOvRrH+bBadobHQw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=UKIY1O5DmqMG8AJ9ZHv86Qd1/zexP4pXu62ROXtvx9D7jZTpaJnClAzufeb/ufJsD ezyQSHjcSZIEv5qPml+NPcphKFEX3W3WhQvD+fxMg4UT9zAy16S/V6msDY5cpITPko l0fvsgnryVK00r92aSbZbN4FPWWmH8CPPqn52aTlwYi75J+Nie4ArgFa5GyiI5bsVq NkUF/y5PcVHop5xmIabNjspjkb4McaOqVcsfKcLiMrh+cLbZPu0uAQInPW2IHlP93z s74g+VbfxDbQLPYZHTSL0p1lseyHKfrdjm4K9lLXLdH1E8A/P4/UllhVis1lCgKrym m8pDSWDvpNmYg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4THw70391Pz9rxG; Sun, 21 Jan 2024 15:03:24 +0100 (CET) In-Reply-To: Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:315176 Archived-At: Richard Stallman writes: > 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)))) Yes. > What cond* cannot do is apply `and' to two different match* clauses > which test different objects. I could add that capability. You understand correctly - `and' for different match* clauses is what I pointed to. > ... 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. `app' is actually a more limited version of what you can do when combining multiple match* clauses - match* clauses can test completely unrelated objects, while pcase's `app' can only test a transformed first pcase argument. So, I do not think that `app' is required if combining match* clauses is allowed. > 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. I looked up the use of pcase's `app' pattern across the packages I use and inside Emacs source code. There are only several trivial uses, actually: (defun engrave-faces-preset-style (faces) "Return the preset style for FACES, should it exist. Unconditionally returns nil when FACES is default." (pcase faces ('default nil) ((pred symbolp) (assoc faces engrave-faces-preset-styles)) ((and (pred listp) (app length 1)) ; <--- here (assoc (car faces) engrave-faces-preset-styles)))) (defun octave--indent-new-comment-line (orig &rest args) (pcase (syntax-ppss) ((app ppss-string-terminator ?\') (user-error "Cannot split a single-quoted string")) ((app ppss-string-terminator ?\") (insert octave-string-continuation-marker)) ((pred (not ppss-comment-depth)) (delete-horizontal-space) (unless (octave-smie--in-parens-p) (insert " " octave-continuation-string)))) (apply orig args) (indent-according-to-mode)) and a couple of internal pcase uses that are there to extend pcase - `rx--pcase-expand', `seq--make-pcase-bindings', `map--make-pcase-bindings', and (pcase-defmacro eieio...) -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at