From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: pcase defuns Date: Thu, 23 Dec 2021 10:30:07 +0800 Message-ID: <87a6gsm4sw.fsf@yahoo.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26680"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: emacs-devel@gnu.org To: Andrew Hyatt Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 23 03:31:37 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 1n0DtJ-0006nM-0U for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Dec 2021 03:31:37 +0100 Original-Received: from localhost ([::1]:54612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n0DtH-0008Qe-Ko for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Dec 2021 21:31:35 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n0Ds6-00070c-EX for emacs-devel@gnu.org; Wed, 22 Dec 2021 21:30:22 -0500 Original-Received: from sonic308-10.consmr.mail.ne1.yahoo.com ([66.163.187.33]:37026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n0Ds3-00009n-SW for emacs-devel@gnu.org; Wed, 22 Dec 2021 21:30:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1640226685; bh=rS1iSh2joMp63j1eyLVRqw6ZBrhsxsbZ77KVhOvX8B8=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=XcwC+RbsWjtgGaA7EXvAKesCN4eTxDKEBppwTisE9PBMakjW8UeAKVfuOjNTnvqp9YNGMCz+kQXCE8+yZ+qEIAR7wFVxRWF9jQh2bKCkKx+WMZWZDKarbCpUuFX5AHw2ipO+R7mS6xcPiAJPCQR4zHqf8JmiPdmSFVGhjUgSG5odgQGyC5VwHZdkabzCpPzfwvfxSXn8jUi0ElGRVG3DEwsqiVH+GHHFGk3Ig7Bhai3DV/StJsWjQezZVlHRyg9ESItJzj5/YKVaa7ybabcye9wDKfzh33lkPOPbeNLi4PfVfLyNRDwhg4NXm6f0TjnkFuYMmr8y+pvR0ZreBIAMHQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1640226685; bh=u+VBOM1DJlNzGH0kJRd+fzwiZ8Oc5l2ouNjIldovTGh=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=EYSx0bfFHIa3W0c6lf4M76+WjhnaE9GSvtPcQ7Wtbk6rWv0X41QKFV4LIZVP7MJU0FdOEGR1QYWnOFAF8nwQLIx3tHli+UKISn+1KasLsCq7TIlIP7MDR2wgu0EVBLrsftHqKi+gzztifQwTlV7bNItyy4exOgSxWMlWDIr7VbowMLYXf2cmiNjuix3RDECaS6gWsLzyDHOBT5sxXQU8OpcBHyFR+b+31ou89J6CB46A1FY4/RuSxdS2iteayTvzRVs4f5vVpc9G7V1Jdl+d6kVq7vNGYAt3fmDFpNj2Mev+Ix6iVUzbO5Si5N1j8zrE42+5tpxl2RuToI2BqCT8lA== X-YMail-OSG: Suoz5xwVM1mrcZJmWp_r5HnirT3dMj5w6VOV19zTjfu7QFxehQIUt4dLFEfcvR2 b8zSJF0IcK6juBvXkJWsqwMVHD4PxuuBXH_0DzwtTfpdf2mcb8YRHiOaUDLwM0R5x90WjClgVBjO QWOm4QpbyWl.SFfpR6tgrIQ.kAPY7E7X0BKpNM7ETJuUIvaTUl2JqvRK9uFg8sDS.0L6pLOukL.3 IbAO48mfqoS2w7oVk1AZk_OqYLRwB33o8H0dA5wZYzGclzphkh5XQsaadMapJbRdBY42YB3LckT7 sQJAdYrncx8NWtkEUiEE5Fxi7HnpX0PDPPGgVJui6LuBPlmCzZxLYeZrARbNkmyoqI3TangCUjh. KX4H_omCPzBEyewQiSRPesSGIAWotr3pbtVIHIC..pAdmssas0mMby15I2CbYl2aHTP8sIZdFDUy 4btVJtqmBx2lAFYPrmA57KcGJjUP8ZMnc7lXP_RScB3RSehLGefRkOGps4_fkfrCRrxIEu5VAQ_m 94su8ClrlBdtziXFKjI1g6pG4UleAK847dGfGgcfzebQJrK8pow962R5IphF6W6VpdTk0QBnQKqC 5mipTK__uokSqZ3QD88pT892FjV1PVuwdq7sf1HGizC43ceCQ8hR5Hd7Gz2ZDr93ZSykaR.H0LuF Is2IGq662737nXOWXGPsr8Gw3HBu3..56MPGL.97sa9neP6rV1mPnifZJzgvyDkA5bhi1TB.Tws_ 0dIvQ.X5hykGZ.QVw1VLUy1f29NG1suPGhhb3jWF3gLq_Ibk33kgrPfxCLp204mjX2xzVQtFFTyA _NVQM4_FxQ0f73ZWfRb8h84GIxUwJMT9oohx7DuMpw X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Thu, 23 Dec 2021 02:31:25 +0000 Original-Received: by kubenode516.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 5670fc18dda17c779b9e2e399ed4237c; Thu, 23 Dec 2021 02:30:12 +0000 (UTC) In-Reply-To: (Andrew Hyatt's message of "Sat, 18 Dec 2021 23:53:10 -0500") X-Mailer: WebService/1.1.19498 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.187.33; envelope-from=luangruo@yahoo.com; helo=sonic308-10.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" Xref: news.gmane.io gmane.emacs.devel:282859 Archived-At: Andrew Hyatt writes: > Hi all, > > As a part of a personal project, I wrote a way to define functions in > an equivalent way to pcases. For example: > > (pcase-defun mytest (a b _) > "Match on 'a 'b with the third argument a wildcard" > "a b match") > > (pcase-defun mytest (c ,var _) > "Match on 'c binding VAR, with the third argument a wildcard" > (format "c %s match" var) ) > > (mytest 'a 'b 'c) -> "a b match" > (mytest 'c 100 'c) -> "c 100 match" > > This is all accomplished by a few small but tricky macros and a > hashtable that holds all the rules. > > I find this method of programming quite useful for certain kinds of > problems, and pcase is close to what I want, but using pcase forced me > to encapsulate all of my pattern matching logic in one function. Being > able to have it spread out in pattern matching functions seems much > nicer to me. > > If this is of interest, I can either add this to the pcase module > itself, create a package in gnu elpa, or (if there's some reason that > it shouldn't be done) just keep it in a personal repository. > > I'll wait for some guidance before creating a final version, with > tests, wherever it should go. That would be awfully confusing, even more so than CL generic functions. It would make locating the right definition of a function an unwarranted chore. With a generic function, the methods can usually be found by a simple search and are usually obvious from context, and the calling convention is readily available. That is confusing enough, but with these "pcase defuns", there is no standard calling convention to advertise. Now imagine if these pcase defuns are scattered over different files. I think the better solution is to do something like this: (defun foo (&rest args) (pcase args ... That avoids most of the confusion mentioned above.