From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Hyatt Newsgroups: gmane.emacs.devel Subject: pcase defuns Date: Sat, 18 Dec 2021 23:53:10 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14789"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 19 05:53:57 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 1myoCr-0003if-DV for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Dec 2021 05:53:57 +0100 Original-Received: from localhost ([::1]:58964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myoCq-00010B-4q for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Dec 2021 23:53:56 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myoCA-0008T9-V4 for emacs-devel@gnu.org; Sat, 18 Dec 2021 23:53:14 -0500 Original-Received: from [2607:f8b0:4864:20::82e] (port=39774 helo=mail-qt1-x82e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1myoC9-0002tk-F1 for emacs-devel@gnu.org; Sat, 18 Dec 2021 23:53:14 -0500 Original-Received: by mail-qt1-x82e.google.com with SMTP id l8so6765683qtk.6 for ; Sat, 18 Dec 2021 20:53:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=CGhUuB2hbmD2PJ+SVXNcZ3A8795YsHFM35eSsL4hYwU=; b=Z65dlIhKS6BRdzOx2YyPxKzxqwL3NlSNNoVZOsPbmGfOdF0JEYQc6QuBHT2GIVTmX/ JJcZaMsa+M/QAuKpUEfq+mFueCC92+eNoViIfk+tkGwFl6mOWEyW3iJ1LHXednnH/sE5 cOztTov14PCeQuLmAXwhIVWk+riaLq4RZxPWLqooBsur4CtddBDNdGFXzHXreOc9Zks2 5xKO8vj6bXdm26uzP/0zmZz8A6c/+/V0XAl0ghB0UjspE5XPXb/vfsIabTZmCVLWa7FW NUdPF4K0ZnpioN19P96XmmH+paQW9TO8R7RGYMqXQPeav5rQXzWv4tvBt3tfHmxfaqN7 DsqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=CGhUuB2hbmD2PJ+SVXNcZ3A8795YsHFM35eSsL4hYwU=; b=qNX/W4VeFIAe9FQaQC4KXySYlYChoyRbkQf4AHcKRBniMaOJO5gPaxPWseWOOUS99a zA91pi5Qb0s9z2WekATMVo9ayB77ZypImtlYleaRqxNhQaUKpX7QcziSIqKBDVWgw88T E1Qy+wz1ARh63G7CiNx+NdK189Ck5r1/8ldghRLHxHSMXNJXesQ3nYWuDsTy+6mtd3M4 CX5xZQ9y7XfiT/KTF81pxYADrHnN6kBiHOG+JHmHNr90SBjY2WPfNJ2L2O0NWLPrk1LS sNTLnrRRSBo8V8WGIygc/g3Wxqv77W1GGiTEqRj0n0Uzze6Rw3+XGabML6o8yARBfAhB vIjg== X-Gm-Message-State: AOAM531kaMJnAW0iOs1hm6siY1DbOxyXA0a9PSBlk+QVdT4/p773EcGU U5bz0kc3TlbtJMYzhvmhY2JZz1b9nik= X-Google-Smtp-Source: ABdhPJzjssufQnuwnGmSJVSpZ/t0V/3NaCQbOUWdS+AWkNcVjuxh/d3kUhKL+6+meqoHsixDhIVefw== X-Received: by 2002:ac8:4e4f:: with SMTP id e15mr8145587qtw.168.1639889591314; Sat, 18 Dec 2021 20:53:11 -0800 (PST) Original-Received: from andrews-mbp.lan (pool-108-14-78-80.nycmny.fios.verizon.net. [108.14.78.80]) by smtp.gmail.com with ESMTPSA id bs16sm8467705qkb.45.2021.12.18.20.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 20:53:10 -0800 (PST) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::82e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=ahyatt@gmail.com; helo=mail-qt1-x82e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:282358 Archived-At: 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.