From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: pcase defuns Date: Sun, 19 Dec 2021 09:34:40 +0100 Message-ID: <871r299e5j.fsf@gnu.org> 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="22552"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.5; emacs 29.0.50 Cc: emacs-devel@gnu.org To: Andrew Hyatt Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 19 09:46:10 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 1myrpY-0005c2-OB for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Dec 2021 09:46:08 +0100 Original-Received: from localhost ([::1]:38192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myrpX-00050m-BY for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Dec 2021 03:46:07 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:53034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myroi-0003ps-OF for emacs-devel@gnu.org; Sun, 19 Dec 2021 03:45:16 -0500 Original-Received: from [2001:470:142:3::e] (port=55344 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myroi-0007C4-G6; Sun, 19 Dec 2021 03:45:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=xsVbYdmGcuaqTgBo8T0kmHjBB5wD8glMPRaXHdgEWnI=; b=oz56ybQ+Py7ovo 02fli+X6Vy/8KFLickz0hYZtmH0MXqARRDdXGx5Mky7p1VQR/FqVjyf/6jOzGwKZIUIF/yU1Uiraj xYQhzjhUbRWTcPhqpHRigXp1cDCEzm6+W3Nti26RzGCMKSf0qTiIEeSLqMn7KCkpmobTIQsU/LGpy jzTVAxqaDRfc3lLsICuSZZsXbbzWPFTr4YleG5nTJOB9+P4GXsDeXqkSCUhLb5iw2sTn4FFl6ZDKV Cc8KmuV/kvyUSAosDX6gJ9NdFonjtqzrsdcXZU5A3QlwJPgCAoNnYNKCRUNkyxp4/QultAsGVnwxs 1HqnsPFv5vrouM0IEADA==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:33171) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1myroi-00032Q-LU; Sun, 19 Dec 2021 03:45:16 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 77F8527C0054; Sun, 19 Dec 2021 03:45:15 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 19 Dec 2021 03:45:15 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrleelgdduvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhi lhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecuggftrfgrthhtvghrnhepve evieekteekveeigfefffeivdetgeduvdffueeuudevgedttdehvdfhueevfffhnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnhdomh gvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeehvdel kedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 19 Dec 2021 03:45:14 -0500 (EST) In-reply-to: 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:282381 Archived-At: Andrew Hyatt writes: Hi Andrew, > 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" So that's basically similar to cl-defgeneric / cl-defmethod just with pcase pattern matching, right? In that case, I think I like the cl approach better, i.e., having a separate definition for the signature + several implementations for variants. But since the order of patterns is very significant, I'm not sure if it's a good idea to specify them separately. E.g., what if there are pcase-defun's for mytest in several files? Then you might get different behavior depending on the order how files are loaded. And even in the "all patterns in mytest.el" case: what if I re-evaluate some pcase-defuns after the file has been loaded? So probably I'd favor a pcase-defun which specifies all patterns and bodies in a single definition, e.g., like: (pase-defun mytest "Docstring" ((a b _) "a b match") ((c ,var _) (format "c %s match" var))) Bye, Tassilo