From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: map.el: pcase plist keyword-only binding improvement Date: Sun, 02 Feb 2020 03:37:34 -0600 Message-ID: <878sll2uu9.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="105236"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Feb 02 10:38:11 2020 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 1iyBhi-000RGK-TT for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Feb 2020 10:38:10 +0100 Original-Received: from localhost ([::1]:54474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyBhh-0003cp-Vo for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Feb 2020 04:38:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35986) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyBhG-0003BN-CX for emacs-devel@gnu.org; Sun, 02 Feb 2020 04:37:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyBhF-0004J2-DV for emacs-devel@gnu.org; Sun, 02 Feb 2020 04:37:42 -0500 Original-Received: from ciao.gmane.io ([159.69.161.202]:56000) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyBhF-0004Gm-7m for emacs-devel@gnu.org; Sun, 02 Feb 2020 04:37:41 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1iyBhD-000QYk-Ck for emacs-devel@gnu.org; Sun, 02 Feb 2020 10:37:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 159.69.161.202 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:244818 Archived-At: Hi, One of the features I find very useful in dash.el's `-let' macro is its ability to bind plist values to variables of the same names as the keys. With map.el's `pcase' support, Emacs's `pcase' and `pcase-let' can do this as well, but in a less convenient way, because it requires writing both the keyword and the variable name. However, with a simple change to one of map'el's functions, it can support keyword-only plist binding as well. Example usage before change: #+BEGIN_SRC elisp (let ((pl '(:one 1 :two 2))) (pcase pl ((map :one (:two two)) (list one two)))) ;;=> nil (pcase-let* (((map :one (:two two)) '(:one 1 :two 2))) (list one two)) ;;=> (void-variable one) #+END_SRC Changed function: #+BEGIN_SRC elisp (defun map--make-pcase-bindings (args) "Return a list of pcase bindings from ARGS to the elements of a map." (seq-map (lambda (elt) (cond ((consp elt) `(app (pcase--flip map-elt ,(car elt)) ,(cadr elt))) ((keywordp elt) ;; New clause for keyword-only elements. (let ((var (intern (substring (symbol-name elt) 1)))) `(app (pcase--flip map-elt ,elt) ,var))) (t `(app (pcase--flip map-elt ',elt) ,elt)))) args)) #+END_SRC Example usage after change: #+BEGIN_SRC elisp (let ((pl '(:one 1 :two 2))) (pcase pl ((map :one (:two two)) (list one two)))) ;;=> (1 2) (pcase-let* (((map :one (:two two)) '(:one 1 :two 2))) (list one two)) ;;=> (1 2) #+END_SRC Assuming that this change is acceptable, I would like to prepare a patch, which would probably need to include NEWS and documentation changes. However, since the change is to map.el rather than pcase.el, and since map.el is also available on ELPA, I'm not sure how to proceed with those parts, where to make the appropriate documentation changes, etc. Please let me know if this proposal is acceptable and how I should proceed. Thanks, Adam