From unknown Sat Aug 16 00:29:51 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#27584 <27584@debbugs.gnu.org> To: bug#27584 <27584@debbugs.gnu.org> Subject: Status: 26.0.50; alist-get: Add optional arg TESTFN Reply-To: bug#27584 <27584@debbugs.gnu.org> Date: Sat, 16 Aug 2025 07:29:51 +0000 retitle 27584 26.0.50; alist-get: Add optional arg TESTFN reassign 27584 emacs submitter 27584 Tino Calancha severity 27584 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 04 23:23:09 2017 Received: (at submit) by debbugs.gnu.org; 5 Jul 2017 03:23:09 +0000 Received: from localhost ([127.0.0.1]:52798 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSauC-0007ZQ-IW for submit@debbugs.gnu.org; Tue, 04 Jul 2017 23:23:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSauA-0007Yo-9f for submit@debbugs.gnu.org; Tue, 04 Jul 2017 23:23:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSau3-0000dn-7Q for submit@debbugs.gnu.org; Tue, 04 Jul 2017 23:23:01 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:44744) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dSau3-0000da-3a for submit@debbugs.gnu.org; Tue, 04 Jul 2017 23:22:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSau1-00082l-5e for bug-gnu-emacs@gnu.org; Tue, 04 Jul 2017 23:22:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSatw-0000Pe-Pl for bug-gnu-emacs@gnu.org; Tue, 04 Jul 2017 23:22:57 -0400 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:32898) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSatw-0000Kd-GW for bug-gnu-emacs@gnu.org; Tue, 04 Jul 2017 23:22:52 -0400 Received: by mail-pf0-x231.google.com with SMTP id e7so122681700pfk.0 for ; Tue, 04 Jul 2017 20:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=ca7T+nt0v2zjbIL7wW6Qe1QKH/NfwVsjFFHXXKt9tPs=; b=WCYAMqTGWPYPBG8U1uwihs3iJy/h3MgaQ3y3eXeWqYxQE6oYTzNOlPB6csiVm0lGfW 5+Ciq5/mfgX9n/aCUhXyRAG45F/Poi0roTN5Jlq8MGK7ZWjc16qA2E5RyHvj8+fKBdNs +OowHLAagRCNesHGKtENYLLsq1IIaE80Dju2TVnrUUrTMlOKpP9ssKHyB4zkYo6by4Km MclnqHRVdmPsBHMFCmKmWrrxOil0XWL75hav8zVNMSxwo7t3X8Pv9KXKRiuIQ0LCwjQP Tkl6qv12C24aVjmtTvrxyVTGhZXm08UWPSdVSp5HOhdLjOALyABvv9+/vWokHs71t1pt 9gww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ca7T+nt0v2zjbIL7wW6Qe1QKH/NfwVsjFFHXXKt9tPs=; b=j8XvxeSsqisY6cfeG+LcZREuEJ7RB7BLxDmgg2QSrODbogdDxw/xSqB/4wFiCK0zOH 4XE69+vc/unm9bB5CwVqmTsqBUl4Nc7FMqVo1tsQoNBhBtdtbS/I7ObxU2lrefpxvYgF HsIo6bmtFjEQUq6t9Ne4+T57TuZnuA/JcT8/JML2NXfDbW5+TmTIkObrBttHjE40SpH1 Hs0sUzzQWPW5+7js2XerqvQOHqosey/0DLRGV5ax8ePZ+iNUPkd0VQaUPG/oDTuYb7bW sgxODdBr7K8b4VoDXz7lq2x0EyZjH1yF6Q9vheRHKt3foFHCCMkJ+7D+T12G/HpK7ojS I9Ww== X-Gm-Message-State: AIVw110RhuaXIgvmfMnaKOoJNbPZPCV1/3ORyxepOReTqE+9tt0Pujyy jkBapH1T6dtBNKl3 X-Received: by 10.84.176.131 with SMTP id v3mr19936664plb.142.1499224969464; Tue, 04 Jul 2017 20:22:49 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id s123sm49575649pgs.2.2017.07.04.20.22.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jul 2017 20:22:48 -0700 (PDT) From: Tino Calancha To: bug-gnu-emacs@gnu.org Subject: 26.0.50; alist-get: Add optional arg TESTFN Date: Wed, 05 Jul 2017 12:22:44 +0900 Message-ID: <87tw2rva7v.fsf@calancha-pc> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Severity: wishlist X-Debbugs-CC: Nicolas Petton , Stefan Monnier Consider the following question: https://emacs.stackexchange.com/questions/33892/replace-element-of-alist-using-equal-even-if-key-does-not-exist/33893#33893 1. The OP wants to update an alist without adding duplicates, 2. but he doesn't want to restrict the lookup in the alist to 'eq'. The OP realized that (setf (alist-get key alist) val) is not an option because, `alist-get' assumes 'eq' in the lookup. Then he writes his own function: ;; docstrig omitted: (defun alist-set (key val alist &optional symbol) (if-let ((pair (if symbol (assq key alist) (assoc key alist)))) (setcdr pair val) (push (cons key val) alist)) alist) * In the same thread, Drew suggests to add an optional arg TESTFN in `alist-get'. * We might also tweak `map.el' so that the following code works: (progn (setq map (list (cons "a" 1) (cons "b" 2))) (require 'map) (map-put map "a" 'foo 'equal) map) => (("a" . foo) ("b" . 2)) ;; Without 'equal in `map-put' that would yield: ;; (("a" . foo) ("a" . 1) ("b" . 2)) --8<-----------------------------cut here---------------start------------->8--- commit 2c020d77c7e74b8ca415cb6370aac5bac86df452 Author: Tino Calancha Date: Wed Jul 5 12:18:53 2017 +0900 alist-get: Add optional arg TESTFN If TESTFN is non-nil, then it is the predicate to lookup the alist. Otherwise, use 'eq' (Bug#27584). * lisp/subr.el (assoc-default): Add optional arg FULL. (alist-get) * lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN. * lisp/emacs-lisp/gv.el (alist-get): Update expander. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the changes. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 8eab2818f9..d2ae3028d8 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,10 +1589,14 @@ Association Lists @end smallexample @end defun -@defun alist-get key alist &optional default remove -This function is like @code{assq}, but instead of returning the entire +@defun alist-get key alist &optional default remove testfn +This function is like @code{assq} when @var{testfn} is @code{nil}, +but instead of returning the entire association for @var{key} in @var{alist}, @w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}. +When @var{testfn} is non-@code{nil}, it returns @var{value} if @var{key} +is equal to the car of an element of @var{alist}. The equality is +tested with @var{testfn}. If @var{key} is not found in @var{alist}, it returns @var{default}. This is a generalized variable (@pxref{Generalized Variables}) that @@ -1640,7 +1644,7 @@ Association Lists @end smallexample @end defun -@defun assoc-default key alist &optional test default +@defun assoc-default key alist &optional test default full This function searches @var{alist} for a match for @var{key}. For each element of @var{alist}, it compares the element (if it is an atom) or the element's @sc{car} (if it is a cons) against @var{key}, by calling @@ -1652,7 +1656,8 @@ Association Lists If an alist element matches @var{key} by this criterion, then @code{assoc-default} returns a value based on this element. -If the element is a cons, then the value is the element's @sc{cdr}. +If the element is a cons, then the value is the element if @var{full} +is non-@code{nil}, or the element's @sc{cdr} if @var{full} is @code{nil}. Otherwise, the return value is @var{default}. If no alist element matches @var{key}, @code{assoc-default} returns diff --git a/etc/NEWS b/etc/NEWS index 83cb73f4a9..dca9809795 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1046,6 +1046,11 @@ break. * Lisp Changes in Emacs 26.1 +** New optional argument FULL in 'assoc-default', to return the full +matching element. + +** New optional argument TESTFN in 'alist-get', 'map-elt' and 'map-put'. + ** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index c5c12a6414..166881a458 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -377,10 +377,12 @@ setf `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) (gv-define-expander alist-get - (lambda (do key alist &optional default remove) + (lambda (do key alist &optional default remove testfn) (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist - (macroexp-let2 nil p `(assq ,k ,getter) + (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) + (assoc-default ,k ,getter ,testfn nil 'full) + (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) (lambda (v) diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index a89457e877..f3850f5844 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -93,11 +93,11 @@ map-let ((arrayp ,map-var) ,(plist-get args :array)) (t (error "Unsupported map: %s" ,map-var))))) -(defun map-elt (map key &optional default) +(defun map-elt (map key &optional default testfn) "Lookup KEY in MAP and return its associated value. If KEY is not found, return DEFAULT which defaults to nil. -If MAP is a list, `eql' is used to lookup KEY. +If MAP is a list, TESTFN is used to lookup KEY if non-nil or `eql' if nil. MAP can be a list, hash-table or array." (declare @@ -106,30 +106,31 @@ map-elt (gv-letplace (mgetter msetter) `(gv-delay-error ,map) (macroexp-let2* nil ;; Eval them once and for all in the right order. - ((key key) (default default)) + ((key key) (default default) (testfn testfn)) `(if (listp ,mgetter) ;; Special case the alist case, since it can't be handled by the ;; map--put function. ,(gv-get `(alist-get ,key (gv-synthetic-place ,mgetter ,msetter) - ,default) + ,default nil ,testfn) do) ,(funcall do `(map-elt ,mgetter ,key ,default) (lambda (v) `(map--put ,mgetter ,key ,v))))))))) (map--dispatch map - :list (alist-get key map default) + :list (alist-get key map default nil testfn) :hash-table (gethash key map default) :array (if (and (>= key 0) (< key (seq-length map))) (seq-elt map key) default))) -(defmacro map-put (map key value) +(defmacro map-put (map key value &optional testfn) "Associate KEY with VALUE in MAP and return VALUE. If KEY is already present in MAP, replace the associated value with VALUE. +When MAP is a list, test equality with TESTFN if non-nil, otherwise use `eql'. MAP can be a list, hash-table or array." - `(setf (map-elt ,map ,key) ,value)) + `(setf (map-elt ,map ,key nil ,testfn) ,value)) (defun map-delete (map key) "Delete KEY from MAP and return MAP. diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166..01c6c1628f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -650,23 +650,27 @@ copy-tree ;;;; Various list-search functions. -(defun assoc-default (key alist &optional test default) +(defun assoc-default (key alist &optional test default full) "Find object KEY in a pseudo-alist ALIST. ALIST is a list of conses or objects. Each element (or the element's car, if it is a cons) is compared with KEY by calling TEST, with two arguments: (i) the element or its car, and (ii) KEY. If that is non-nil, the element matches; then `assoc-default' - returns the element's cdr, if it is a cons, or DEFAULT if the - element is not a cons. + returns the element, if it is a cons and FULL is non-nil, + or the element's cdr, if it is a cons and FULL is nil, + or DEFAULT if the element is not a cons. If no element matches, the value is nil. If TEST is omitted or nil, `equal' is used." (let (found (tail alist) value) (while (and tail (not found)) (let ((elt (car tail))) - (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) - (setq found t value (if (consp elt) (cdr elt) default)))) + (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) + (setq found t + value (cond ((consp elt) + (if full elt (cdr elt))) + (t default))))) (setq tail (cdr tail))) value)) @@ -725,15 +729,18 @@ rassq-delete-all (setq tail tail-cdr)))) alist) -(defun alist-get (key alist &optional default remove) - "Return the value associated with KEY in ALIST, using `assq'. +(defun alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. This is a generalized variable suitable for use with `setf'. When using it to set a value, optional argument REMOVE non-nil means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. - (let ((x (assq key alist))) + (let ((x (if (and testfn (not (eq testfn 'eq))) + (assoc-default key alist testfn nil 'full) + (assq key alist)))) (if x (cdr x) default))) (defun remove (elt seq) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-05 Repository revision: 5d62247323f53f3ae9c7d9f51e951635887b2fb6 From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 05 04:53:42 2017 Received: (at 27584) by debbugs.gnu.org; 5 Jul 2017 08:53:42 +0000 Received: from localhost ([127.0.0.1]:52937 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSg46-0007B8-6Z for submit@debbugs.gnu.org; Wed, 05 Jul 2017 04:53:42 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33733) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSg45-0007Au-3Y for 27584@debbugs.gnu.org; Wed, 05 Jul 2017 04:53:41 -0400 Received: by mail-pg0-f67.google.com with SMTP id u62so30779879pgb.0 for <27584@debbugs.gnu.org>; Wed, 05 Jul 2017 01:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:message-id:mime-version; bh=3aRej7ilQQlU3PmgbYCo6sXrPjWosLcYlKvrizpjcyA=; b=n5SVy8zsoo3xus2OpfGgvgt4FUX1EZKCR0gLM9ti969PrdzTCSjsWOr4THgevRmRjw GMmz7FnzXILvS0RUaxUkGR0B054B0woAhGxlZoA94Jz3PYqzWEtblE9X9odF3rawyeWN 99na39sTsz7VbE2ohhTTV9fAiQieKx/31X+sksm7CqCejHcjf7/qsxY8jol619hmlYEh iUz73eCXcKRTPaDW9rAA8r/HwSzfzcgLF/PnsLnSdYrv8O2hriQTcit9Yz1c9GnvEMkm SRHSQjZI9qjI78hbfqlL7cfBhySw6unRK95PWrCUGyvLQKDlL9hGwERYj3XBUrLsRkcN ktZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:message-id :mime-version; bh=3aRej7ilQQlU3PmgbYCo6sXrPjWosLcYlKvrizpjcyA=; b=lrc5khQin+NBe65JphCHc8R8cUyGsY1kEg99AhTa0K6PDI14np8SRUYqfXQhWceQud K0bXFoNbo5TN8BFqar30rWTALiax2o2NC0mPS8+c4VPF0YhLPGYN7JzcDjjpeLp4Vizg k2fTTp46WPBASsKjye1/IbbuP621AVbpMYwPSZ3Gw2FyVnKD6DCzxklmCT1O4ub7Ifbp SZVLdJ3a6IAvIWNNTV7MwuMKV9nhnzn/9hYKMJS9cfikHvqNTb0Pq/+2L4AAExI9pZiG /y69knuMNjd20ITkkffkCVe7d2N6y3PxIRYoPpdZd5kPB+nmW8B20xcQeLhnEJF7lMRh D5WQ== X-Gm-Message-State: AIVw110cyJqBcsIhLihYbhOAS+2EptWt0MlO9ZUmkaPMY0jE8U12f0Zw /Dej+vWs/uHAAw== X-Received: by 10.84.138.131 with SMTP id 3mr11760902plp.293.1499244815185; Wed, 05 Jul 2017 01:53:35 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id n19sm45378876pfa.64.2017.07.05.01.53.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jul 2017 01:53:34 -0700 (PDT) From: Tino Calancha To: 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> Date: Wed, 05 Jul 2017 17:53:29 +0900 Message-ID: <87k23n8dti.fsf@calancha-pc> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 27584 Cc: nicolas petton , stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) > > -(defun assoc-default (key alist &optional test default) > +(defun assoc-default (key alist &optional test default full) > "Find object KEY in a pseudo-alist ALIST. > ALIST is a list of conses or objects. Each element > (or the element's car, if it is a cons) is compared with KEY by > calling TEST, with two arguments: (i) the element or its car, > and (ii) KEY. > If that is non-nil, the element matches; then `assoc-default' > - returns the element's cdr, if it is a cons, or DEFAULT if the > - element is not a cons. > + returns the element, if it is a cons and FULL is non-nil, > + or the element's cdr, if it is a cons and FULL is nil, > + or DEFAULT if the element is not a cons. > > If no element matches, the value is nil. > If TEST is omitted or nil, `equal' is used." > (let (found (tail alist) value) > (while (and tail (not found)) > (let ((elt (car tail))) > - (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) > - (setq found t value (if (consp elt) (cdr elt) default)))) > + (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) > + (setq found t > + value (cond ((consp elt) > + (if full elt (cdr elt))) > + (t default))))) > (setq tail (cdr tail))) > value)) If we go in this direction, then i think it has sense to add something with less parameters, like this: (defsubst assoc-predicate (key alist test) "Like `assoc' but compare keys with TEST." (assoc-default key alist test nil 'full)) From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 05 05:19:33 2017 Received: (at 27584) by debbugs.gnu.org; 5 Jul 2017 09:19:33 +0000 Received: from localhost ([127.0.0.1]:52962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSgT7-0007m5-DC for submit@debbugs.gnu.org; Wed, 05 Jul 2017 05:19:33 -0400 Received: from petton.fr ([89.234.186.68]:52610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSgT6-0007lr-0e for 27584@debbugs.gnu.org; Wed, 05 Jul 2017 05:19:32 -0400 From: Nicolas Petton To: Tino Calancha , 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87tw2rva7v.fsf@calancha-pc> References: <87tw2rva7v.fsf@calancha-pc> Date: Wed, 05 Jul 2017 11:19:20 +0200 Message-ID: <87mv8j6y1z.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499246364; bh=LYiXoxqBkWxMgqQjJPnxNFJWYoJeWz9MbLRQnUeOH6s=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=aoExXphRZ34PLHLCCcQlxMvGocQjIQpAAZ95gUIz5DiDviTXvM7WZsoTvpp5KlHG1FK+oUtth1fvxhYlGh90RSM/rakSMduGV6F3T0BLr77wkVdy22ug0UOIBg7xXKaYBa2pTAaxY6MxCv6gwQYIRTUFpbbjlDrCCL6MBuEHUCU= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: > Consider the following question: > https://emacs.stackexchange.com/questions/33892/replace-element-of-alist-using-equal-even-if-key-does-not-exist/33893#33893 > > 1. The OP wants to update an alist without adding duplicates, > 2. but he doesn't want to restrict the lookup in the alist to 'eq'. > > The OP realized that > > (setf (alist-get key alist) val) > > is not an option because, `alist-get' assumes 'eq' in the lookup. > Then he writes his own function: > ;; docstrig omitted: > (defun alist-set (key val alist &optional symbol) > (if-let ((pair (if symbol (assq key alist) (assoc key alist)))) > (setcdr pair val) > (push (cons key val) alist)) > alist) > > * In the same thread, Drew suggests to add an optional arg TESTFN in `alist-get'. > * We might also tweak `map.el' so that the following code works: Thanks, I like your changes. If this is going to be installed, could you add tests to map-tests.el as well? Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZXK8YAAoJECM1h6R8IHkQwMAIAL0twb87AKaW7rd+7u3TM7B0 AhEgjvJgYLUpCbJFGDPUViqzSyHkWvPtI4frpW3zyaPSzQ5tGOK4ZUF+W2dPGIFs OmuR5B1+SogMoYkOdL8vHsN8wLClyzDOeuPyngzR24H/D++5wYAaYe5XKVKiYs5b FRO26paBBaAaEWz1Kg+TQ2/t5ziRyf1WfXNvJ3ajOHYXX8k3/SWdNkKfc5BLkZkX Z5VIKtO5xLW7xtOG6UtUTNutPYoMJOcRD3Vham8q4RSfCMNIDctt8M1Rf5hcMBrM YK2IO2/LAc5ZvqEpEnb6SNJlRCQiTCqzLrDUWJdfZ7joweKdf4F0lZsMUISRPRM= =8STH -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 05 09:19:06 2017 Received: (at 27584) by debbugs.gnu.org; 5 Jul 2017 13:19:06 +0000 Received: from localhost ([127.0.0.1]:53089 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSkCv-0006Vi-QF for submit@debbugs.gnu.org; Wed, 05 Jul 2017 09:19:05 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:36131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSkCu-0006VF-1U for 27584@debbugs.gnu.org; Wed, 05 Jul 2017 09:19:04 -0400 Received: by mail-pg0-f51.google.com with SMTP id u62so124274068pgb.3 for <27584@debbugs.gnu.org>; Wed, 05 Jul 2017 06:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=iGV6nAylGAK0TKsUI+8CoAnGwlRqxHBeSnx5XXs+WqI=; b=pMgZt+J5FnAYdMRnULNdlGAkeo8J1HgjDQ6cAmXDDIiwTgrfHcxfp7GuRuiYxRgOVa hEPlwJ+Ge88ivt2MjljbLX6eVEK+MCQxnSzz7RBm9CURPjb29G7hCXa53kmq2pcHrTeJ Fad+2Lix7ss3E6lySPz8uUniblQ2H9YamEulGierhqkRz7Myzm7yOW6H+dBSIM9O/B1Y wZsJcpjhcKeZcDu6YBcuDq3bVO+S+yozPGwu9PDJ5InWcsKu8T2ZvDpr5vJYalQahgFG D2BuLOyYLJ+79uCJj4F1cpkEGCG4M3/F+t5WFsu6BE6Da+Z/Ym+TMZIOjW2mY1j9z9xj epVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=iGV6nAylGAK0TKsUI+8CoAnGwlRqxHBeSnx5XXs+WqI=; b=G2M6zSxIFJeBFRcvCz02TVmHtKgGPaY9rPotdprB9k6VN5k6mFXMq2pe65pRUk9VXq w82KYUdrKadk6BdBEDok1PMcZWLxsR9vDcRaP5vj+Q92houEAndMh0Y+jSjtujpH/G5O AGLL0QPI6m53gb/xQNe8jp68gBIMOM7oMSQk2Xv5Sxw6QhTj6RI1mRbnEhibUc9LIOnK jpTnQ0NWQVpuUot1rdpulteD+jvGXhyErn1kS/zSK7tlejCluNfb4Aydebr814Kz/XZ7 g//+qE9XtzghnKb3UuCdEo7M66BrIqVL1b/x3jLe7D0dWacLwycUKu+DB6weo5nbjbSw CL9A== X-Gm-Message-State: AIVw113ETvTIaldzM5Oc+PNHrdutYk6fBOTSef8syOzGR9dSDPSApUrm SK45g2fcEoiDbw== X-Received: by 10.99.135.73 with SMTP id i70mr21217494pge.74.1499260738059; Wed, 05 Jul 2017 06:18:58 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id d1sm50130496pfj.51.2017.07.05.06.18.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 06:18:57 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Wed, 5 Jul 2017 22:18:53 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87mv8j6y1z.fsf@petton.fr> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, stefan monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) On Wed, 5 Jul 2017, Nicolas Petton wrote: > Thanks, I like your changes. If this is going to be installed, could > you add tests to map-tests.el as well? Sure, i have that in mind. I will prepare them by tomorrow while Stefan take a look on it. Cheers, Tino From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 02:05:32 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 06:05:32 +0000 Received: from localhost ([127.0.0.1]:54078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSzut-0006qA-Qq for submit@debbugs.gnu.org; Thu, 06 Jul 2017 02:05:32 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34317) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSzur-0006pw-Ls for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 02:05:30 -0400 Received: by mail-pg0-f66.google.com with SMTP id j186so1530226pge.1 for <27584@debbugs.gnu.org>; Wed, 05 Jul 2017 23:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=qEr+Qtbn110bsDPhX6KYPskbkh6W8kk57klvGj8wIjQ=; b=XPXH0/nA71h/AEAfOWYskhcId3FRFohpQQOyZ+V/C99ndWLEKDfpZX7KzIcH3YLKS1 JOZyc7zZ85srm7KlhHL0xZsbClevKF7yfSgYK/UoQ5goDLZu+LO9nnivAgmRsZ04J6+v G9oodrdltM25EfjDmaQxefuTZerSWC+s4NaQ64peYu/HOWzYO6yStnqMlY+d3j5QMoea uQhza5KAsPAN/Gssn2aD6wgoLMX18+iLHSUDZqh5zNuqh+CXxfL2ibrLTLVuZg77wozw t7fSgrAwvFqFMZfew4ckCh/f8hoU+ZSVmhzTHl/0N7vWsIsgPrQkXuPDJvpf5VWcipY5 Xfog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=qEr+Qtbn110bsDPhX6KYPskbkh6W8kk57klvGj8wIjQ=; b=dROOh2Pqh4NoW1I7gEAyR1xTFVInhcCqzz9L/Ll9y1vB9Bxsttq5AHdXTFEb3Uznq4 1lkREKiuh51FPEZ+ITDh9nlwNNNZaEaAM2CJBj0/c2KgTRsmx61Kn0w4ahdexvDUWDN2 JcKwo6p5NZnb3Zd2odTPwdmsGLTvb2GG3D9XXmudG2EM5MZdZ8S2gAESYsMInUx83kq8 qVuwZi41KhFkJNJP8WIbV1PCnEwmBcfSS2HrmAMBExBBWjwrZlTDC85vkX+ZSCI3YlRD QzXVR6neWXP2OH9lZmXXvDVj41U3ZkSjbWXsv+uW4ExhwpLGETmULGVQOBpJTEE1yv0L kaxQ== X-Gm-Message-State: AIVw111B47ZuBii0f2goVF3DJrtQiJXkvhYM+KP0bFWlRRMw4OMPmHzc tsR73JyhiiepNQ== X-Received: by 10.99.56.21 with SMTP id f21mr24215815pga.235.1499321123208; Wed, 05 Jul 2017 23:05:23 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id e90sm2095119pfd.75.2017.07.05.23.05.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jul 2017 23:05:22 -0700 (PDT) From: Tino Calancha To: 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> Date: Thu, 06 Jul 2017 15:05:12 +0900 In-Reply-To: (Tino Calancha's message of "Wed, 5 Jul 2017 22:18:53 +0900 (JST)") Message-ID: <87y3s2m76v.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Tino Calancha writes: > On Wed, 5 Jul 2017, Nicolas Petton wrote: > >> Thanks, I like your changes. If this is going to be installed, could >> you add tests to map-tests.el as well? OK, done! (See patch below) I have a few questions: 1. In my patch `assoc-predicate' is a defsubst. Should does exit at all? If yes: *) should be a defun instead? **) should be named `assoc-predicate' or differently? 2. Should i collapse those 3 new 'etc/NEWS' entries in just 1 or 2? --8<-----------------------------cut here---------------start------------->8--- commit a7f6ac2a09de893a42b086ec2dabbeeac7ba4cb4 Author: Tino Calancha Date: Thu Jul 6 14:47:43 2017 +0900 alist-get: Add optional arg TESTFN If TESTFN is non-nil, then it is the predicate to lookup the alist. Otherwise, use 'eq' (Bug#27584). * lisp/subr.el (assoc-default): Add optional arg FULL. (alist-get) * lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN. * lisp/emacs-lisp/gv.el (alist-get): Update expander. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the changes. * test/lisp/emacs-lisp/map-tests.el (test-map-put-testfn-alist) (test-map-elt-testfn): New tests. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 8eab2818f9..d2ae3028d8 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,10 +1589,14 @@ Association Lists @end smallexample @end defun -@defun alist-get key alist &optional default remove -This function is like @code{assq}, but instead of returning the entire +@defun alist-get key alist &optional default remove testfn +This function is like @code{assq} when @var{testfn} is @code{nil}, +but instead of returning the entire association for @var{key} in @var{alist}, @w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}. +When @var{testfn} is non-@code{nil}, it returns @var{value} if @var{key} +is equal to the car of an element of @var{alist}. The equality is +tested with @var{testfn}. If @var{key} is not found in @var{alist}, it returns @var{default}. This is a generalized variable (@pxref{Generalized Variables}) that @@ -1640,7 +1644,7 @@ Association Lists @end smallexample @end defun -@defun assoc-default key alist &optional test default +@defun assoc-default key alist &optional test default full This function searches @var{alist} for a match for @var{key}. For each element of @var{alist}, it compares the element (if it is an atom) or the element's @sc{car} (if it is a cons) against @var{key}, by calling @@ -1652,7 +1656,8 @@ Association Lists If an alist element matches @var{key} by this criterion, then @code{assoc-default} returns a value based on this element. -If the element is a cons, then the value is the element's @sc{cdr}. +If the element is a cons, then the value is the element if @var{full} +is non-@code{nil}, or the element's @sc{cdr} if @var{full} is @code{nil}. Otherwise, the return value is @var{default}. If no alist element matches @var{key}, @code{assoc-default} returns diff --git a/etc/NEWS b/etc/NEWS index 13805ce0da..a395ac7aec 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1050,6 +1050,13 @@ break. * Lisp Changes in Emacs 26.1 ++++ +** New optional argument FULL in 'assoc-default', to return the full +matching element. + ++++ +** New optional argument TESTFN in 'alist-get', 'map-elt' and 'map-put'. + ** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index c5c12a6414..166881a458 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -377,10 +377,12 @@ setf `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) (gv-define-expander alist-get - (lambda (do key alist &optional default remove) + (lambda (do key alist &optional default remove testfn) (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist - (macroexp-let2 nil p `(assq ,k ,getter) + (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) + (assoc-default ,k ,getter ,testfn nil 'full) + (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) (lambda (v) diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index a89457e877..f3850f5844 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -93,11 +93,11 @@ map-let ((arrayp ,map-var) ,(plist-get args :array)) (t (error "Unsupported map: %s" ,map-var))))) -(defun map-elt (map key &optional default) +(defun map-elt (map key &optional default testfn) "Lookup KEY in MAP and return its associated value. If KEY is not found, return DEFAULT which defaults to nil. -If MAP is a list, `eql' is used to lookup KEY. +If MAP is a list, TESTFN is used to lookup KEY if non-nil or `eql' if nil. MAP can be a list, hash-table or array." (declare @@ -106,30 +106,31 @@ map-elt (gv-letplace (mgetter msetter) `(gv-delay-error ,map) (macroexp-let2* nil ;; Eval them once and for all in the right order. - ((key key) (default default)) + ((key key) (default default) (testfn testfn)) `(if (listp ,mgetter) ;; Special case the alist case, since it can't be handled by the ;; map--put function. ,(gv-get `(alist-get ,key (gv-synthetic-place ,mgetter ,msetter) - ,default) + ,default nil ,testfn) do) ,(funcall do `(map-elt ,mgetter ,key ,default) (lambda (v) `(map--put ,mgetter ,key ,v))))))))) (map--dispatch map - :list (alist-get key map default) + :list (alist-get key map default nil testfn) :hash-table (gethash key map default) :array (if (and (>= key 0) (< key (seq-length map))) (seq-elt map key) default))) -(defmacro map-put (map key value) +(defmacro map-put (map key value &optional testfn) "Associate KEY with VALUE in MAP and return VALUE. If KEY is already present in MAP, replace the associated value with VALUE. +When MAP is a list, test equality with TESTFN if non-nil, otherwise use `eql'. MAP can be a list, hash-table or array." - `(setf (map-elt ,map ,key) ,value)) + `(setf (map-elt ,map ,key nil ,testfn) ,value)) (defun map-delete (map key) "Delete KEY from MAP and return MAP. diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166..01c6c1628f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -650,23 +650,27 @@ copy-tree ;;;; Various list-search functions. -(defun assoc-default (key alist &optional test default) +(defun assoc-default (key alist &optional test default full) "Find object KEY in a pseudo-alist ALIST. ALIST is a list of conses or objects. Each element (or the element's car, if it is a cons) is compared with KEY by calling TEST, with two arguments: (i) the element or its car, and (ii) KEY. If that is non-nil, the element matches; then `assoc-default' - returns the element's cdr, if it is a cons, or DEFAULT if the - element is not a cons. + returns the element, if it is a cons and FULL is non-nil, + or the element's cdr, if it is a cons and FULL is nil, + or DEFAULT if the element is not a cons. If no element matches, the value is nil. If TEST is omitted or nil, `equal' is used." (let (found (tail alist) value) (while (and tail (not found)) (let ((elt (car tail))) - (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) - (setq found t value (if (consp elt) (cdr elt) default)))) + (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) + (setq found t + value (cond ((consp elt) + (if full elt (cdr elt))) + (t default))))) (setq tail (cdr tail))) value)) @@ -725,15 +729,18 @@ rassq-delete-all (setq tail tail-cdr)))) alist) -(defun alist-get (key alist &optional default remove) - "Return the value associated with KEY in ALIST, using `assq'. +(defun alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. This is a generalized variable suitable for use with `setf'. When using it to set a value, optional argument REMOVE non-nil means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. - (let ((x (assq key alist))) + (let ((x (if (and testfn (not (eq testfn 'eq))) + (assoc-default key alist testfn nil 'full) + (assq key alist)))) (if x (cdr x) default))) (defun remove (elt seq) diff --git a/test/lisp/emacs-lisp/map-tests.el b/test/lisp/emacs-lisp/map-tests.el index 07e85cc539..15b0655040 100644 --- a/test/lisp/emacs-lisp/map-tests.el +++ b/test/lisp/emacs-lisp/map-tests.el @@ -63,6 +63,11 @@ with-maps-do (with-maps-do map (should (= 5 (map-elt map 7 5))))) +(ert-deftest test-map-elt-testfn () + (let ((map (list (cons "a" 1) (cons "b" 2)))) + (should-not (map-elt map "a")) + (should (map-elt map "a" nil 'equal)))) + (ert-deftest test-map-elt-with-nil-value () (should (null (map-elt '((a . 1) (b)) @@ -94,6 +99,13 @@ with-maps-do (should (eq (map-elt alist 2) 'b)))) +(ert-deftest test-map-put-testfn-alist () + (let ((alist (list (cons "a" 1) (cons "b" 2)))) + (map-put alist "a" 3 'equal) + (should-not (cddr alist)) + (map-put alist "a" 9) + (should (cddr alist)))) + (ert-deftest test-map-put-return-value () (let ((ht (make-hash-table))) (should (eq (map-put ht 'a 'hello) 'hello)))) commit 4bb22ad2203ac54e5f873fcf624e26642e1557c1 Author: Tino Calancha Date: Thu Jul 6 14:48:44 2017 +0900 assoc-predicate: New defsubst * lisp/subr.el (assoc-predicate): New defsubst. (alist-get): * lisp/emacs-lisp/gv.el (alist-get): Use it. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the feature. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index d2ae3028d8..98a79990a4 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,6 +1589,24 @@ Association Lists @end smallexample @end defun +@defun assoc-predicate key alist test +This function is like @code{assoc} in that it returns the first +association for @var{key} in @var{alist}, but it makes the comparison +using @code{test} instead of @code{equal}. @code{assoc-predicate} +returns @code{nil} if no association in @var{alist} has a @sc{car}, +@var{x}, satisfying @code{(funcall test x key)}. + +@smallexample +(setq leaves + '(("simple leaves" . oak) + ("compound leaves" . horsechestnut))) + +(assoc-predicate "simple leaves" leaves 'string=) + @result{} ("simple leaves" . oak) +@end smallexample + +@end defun + @defun alist-get key alist &optional default remove testfn This function is like @code{assq} when @var{testfn} is @code{nil}, but instead of returning the entire diff --git a/etc/NEWS b/etc/NEWS index a395ac7aec..4d23563215 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1051,6 +1051,9 @@ break. * Lisp Changes in Emacs 26.1 +++ +** New defsubst 'assoc-predicate'. + ++++ ** New optional argument FULL in 'assoc-default', to return the full matching element. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 166881a458..29b85e280e 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -381,7 +381,7 @@ setf (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) - (assoc-default ,k ,getter ,testfn nil 'full) + (assoc-predicate ,k ,getter ,testfn) (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) diff --git a/lisp/subr.el b/lisp/subr.el index 01c6c1628f..1d1f39731f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -674,6 +674,10 @@ assoc-default (setq tail (cdr tail))) value)) +(defsubst assoc-predicate (key alist test) + "Like `assoc' but compare keys with TEST." + (assoc-default key alist test nil 'full)) + (defun assoc-ignore-case (key alist) "Like `assoc', but ignores differences in case and text representation. KEY must be a string. Upper-case and lower-case letters are treated as equal. @@ -739,7 +743,7 @@ alist-get means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. (let ((x (if (and testfn (not (eq testfn 'eq))) - (assoc-default key alist testfn nil 'full) + (assoc-predicate key alist testfn) (assq key alist)))) (if x (cdr x) default))) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-06 Repository revision: 7a0170de20fe1225d3eeac099d1e61a0c0410bf3 From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 02:13:15 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 06:13:15 +0000 Received: from localhost ([127.0.0.1]:54082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT02M-00070P-UF for submit@debbugs.gnu.org; Thu, 06 Jul 2017 02:13:15 -0400 Received: from chene.dit.umontreal.ca ([132.204.246.20]:47133) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT02L-00070H-GP for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 02:13:13 -0400 Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id v666DAtW032423; Thu, 6 Jul 2017 02:13:11 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 506F666273; Thu, 6 Jul 2017 02:13:10 -0400 (EDT) From: Stefan Monnier To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> Date: Thu, 06 Jul 2017 02:13:10 -0400 In-Reply-To: <87y3s2m76v.fsf@calancha-pc> (Tino Calancha's message of "Thu, 06 Jul 2017 15:05:12 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6064=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6064> : inlines <5963> : streams <1752974> : uri <2457055> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) > 1. In my patch `assoc-predicate' is a defsubst. > Should does exit at all? > If yes: > *) should be a defun instead? > **) should be named `assoc-predicate' or differently? It's been called cl-assoc so far ;-) Stefan From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 02:20:59 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 06:21:00 +0000 Received: from localhost ([127.0.0.1]:54098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT09r-0007CN-NZ for submit@debbugs.gnu.org; Thu, 06 Jul 2017 02:20:59 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34385) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT09q-0007CB-Gy for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 02:20:58 -0400 Received: by mail-pf0-f194.google.com with SMTP id c24so1785327pfe.1 for <27584@debbugs.gnu.org>; Wed, 05 Jul 2017 23:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=hD3lAhZKzGQehFp2t87x903T/L75wC3g8dZRz33ekVg=; b=JDN6A1W+gMuY7xwpwfiCY6ZEHpxOeG5hx1lejpYeQxeWEOlnFpptXSn+Ympsz673UP PzJt4BhoZ2R5to8U/DmJiqEDiOiHVd47MRzYCgC61Cpf9DHCIc0gXDjiXye3zDi4VXZU /5r7xXZ5me93Vv5DmAzPodzUHi0sppw/skRiNkWOR+c0HBxdfw2+GSkkY3StjzgU3v7v BlWEdAvJjOY2rbodGqkhUeyRkqwmZ/yTRlSg+X4lxxOgjV5dWa5AV8Ri9R/56SuohztW wJskokPiUlH1VmbX4PhfIE5REdNvPetNG1CCvIF3na1CB84z0E7fA7EcsM+v/U0BpzcO +uyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=hD3lAhZKzGQehFp2t87x903T/L75wC3g8dZRz33ekVg=; b=p3yz7xFR15nB4Kt0mZ+lqWXY3WvDm+IGaWEyVtlB1SzuMSI9x/+qRhsZ7xTJg6V9FZ tkK7GZUy3KJ7jDi+CRfSXOx9+0QRMdNccStoLtXUrAJB294/gEY4+SiyPx3kWV+Rl/YO WtpmVuuiIKVYbZ6O+Yvrc/CXXJ6Q9mjPAR7Z29Hh6HhiaKqgcLy4PObuwYf0NckH6qrK 3RlFiOnJMWbH33IKDP95kM+mrMjb7FNr0zEYTuSllB2K1GuD2/OPfX/aQnhb/GVEgVrn W7owv2+VqmBGoSPVDheAyaWx2QTFl73Tc+XGkpSrdfRzNbu9h2SqAA8/oTjI83PtWFn3 opwA== X-Gm-Message-State: AIVw110BukLboNAIgI00y7gUxUHgSl1PC+8KFXWpb+YS1TyOMNPyWJ+T 7ymORgVYjAE/pw== X-Received: by 10.98.220.26 with SMTP id t26mr24403629pfg.32.1499322052923; Wed, 05 Jul 2017 23:20:52 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id o84sm2132590pfj.109.2017.07.05.23.20.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 23:20:52 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Thu, 6 Jul 2017 15:20:49 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Stefan Monnier Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Thu, 6 Jul 2017, Stefan Monnier wrote: >> 1. In my patch `assoc-predicate' is a defsubst. >> Should does exit at all? >> If yes: >> *) should be a defun instead? >> **) should be named `assoc-predicate' or differently? > > It's been called cl-assoc so far ;-) Some day your dream will be fulfilled, and `cl-lib' will be preloaded at startup. Then, we will not need things like `assoc-predicate'. From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 05:36:24 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 09:36:24 +0000 Received: from localhost ([127.0.0.1]:54202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT3Cy-0004yA-Nn for submit@debbugs.gnu.org; Thu, 06 Jul 2017 05:36:24 -0400 Received: from petton.fr ([89.234.186.68]:36114) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT3Cw-0004xw-KF for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 05:36:23 -0400 From: Nicolas Petton To: Tino Calancha , Stefan Monnier Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> Date: Thu, 06 Jul 2017 11:36:12 +0200 Message-ID: <87van56h6b.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499333776; bh=BWufZSfAYUwNEC2Cw74gBISopelxJnKoCG78O5OfDBs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=Z/f28I8vGSux4BW45DIPnHngEeruXfV7DLgtMfRRVfBlTOCKpvO2jhLX0KANfwFkHLtA2z1tk7frjgyFWjkI33Sqy2vmUszOP8Ew3w0/u1GJ9Q4vV6FprYBiuVcdKBjIlRClK5JweWQs2W3E36pzuzHExMXE4Dklq8ZvJ5FYX9I= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Tino Calancha writes: >> It's been called cl-assoc so far ;-) > Some day your dream will be fulfilled, and `cl-lib' will be preloaded at > startup. Then, we will not need things like `assoc-predicate'. map.el could require cl-lib and use cl-assoc?=20 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZXgSMAAoJECM1h6R8IHkQYPwIALztkGh9bw8KTvKpE5XHDmI7 7YZh2ht4IR1wieoa0kLxkJzXtv+tP0kGHkFT8jcwcagSJNPGHEZtK//n7VJ9lyCY gph1Y7tqIPYCmg2bEeIqHcrFjhBw3BXPSD+ZoYmWlQdKEXiwqrfjJv5wrUs1lEBI mCH/bPxVwAbApP8O/tlLawkQySggYp0K17geQSifl28QwYAe8NzzCLETCTKvcOAV 4KtjJYNWrJni/PKnrbMpz3m9IU2FJCxiNmm+w41oIf+FwqSsLXAF1htO3TpQzxpQ s4QGj/g7gp3aFiI2u36mfv7DlOiR7stuVvM8eL/ymJDR798mNk0f7rlULLWTrd8= =O8NS -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 06:55:25 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 10:55:25 +0000 Received: from localhost ([127.0.0.1]:54263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT4RQ-0006xD-UQ for submit@debbugs.gnu.org; Thu, 06 Jul 2017 06:55:25 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34237) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT4RP-0006x0-Kh for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 06:55:24 -0400 Received: by mail-pf0-f195.google.com with SMTP id c24so2779098pfe.1 for <27584@debbugs.gnu.org>; Thu, 06 Jul 2017 03:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=BAgpUij3bF/geC6YclqVmccIOaubQJbZgrHtAigxiO0=; b=HhDDLAc87A06D1JIuASbnho0mCQhlqZTzBpeqiJEH84ukxVBcNhGbEaG+T33TFpCKT ITqaFD9KWBqJkDerc1Ey5bdi4LTXrG3SenoK/kqONthWev9VSUu2o/HMIl1BzirRAG7l SQaCE3DmmhA8LDndqvJUgWTqTMNRK/OeIi2yJvql0o+Uvga9AG4+rZOJe0zQEKwxidnH AJ2uwtbHp+v73MYc3F5ubxolLgcFa2Sig3soexEbaus4Jmp07OncqXrEqRQULj+/pHMZ LMpkuhWNKbsHKbhN55nk3T864ryrCZmloBWYYzQAwBnxTpKRF4M0DP9kKeh9dgIo+GfL /BRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=BAgpUij3bF/geC6YclqVmccIOaubQJbZgrHtAigxiO0=; b=KaYBbLmfLj/nGhiYbf9c3siPh7r8fvm3uo6krQDjLrOPZc2i4Nc16csOjyABxsCzd0 uw6A85dOsGA3u3WS+NO2oIElAk5J5Sm9m/oybbtf8OZmrJrusUkQzWwr2saA2TVR/Qm2 7t7iR7JMYSnBdyaOoqmBjmr3dqf0q9sBAGZs4ilKQRqyJKAK1HNVSkxVeAKwcH/bUGG7 DIRT5OcbxaUViafvnqjx2M/tlbTrCy0vZvqJacj/l4iXY5GjKYVE5GpU1/CS8ZcT7ZKi t3hOmmfowrv0W6a3a++maUYmRImD5XgpqcUQEJEvVP3auboP3N5EK/yg5KP8O+tjsOFF CPQQ== X-Gm-Message-State: AIVw111lmRtwJ/ApmCIHr0oezKLf+K4LKPW1kaunivKUsD0XdaPXXjll xhSHa7Jv6S+Eng== X-Received: by 10.98.224.11 with SMTP id f11mr25576866pfh.118.1499338517782; Thu, 06 Jul 2017 03:55:17 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id g73sm4322633pfk.19.2017.07.06.03.55.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jul 2017 03:55:17 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Thu, 6 Jul 2017 19:55:08 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87van56h6b.fsf@petton.fr> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <87van56h6b.fsf@petton.fr> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Stefan Monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Thu, 6 Jul 2017, Nicolas Petton wrote: > Tino Calancha writes: > >>> It's been called cl-assoc so far ;-) > >> Some day your dream will be fulfilled, and `cl-lib' will be preloaded at >> startup. Then, we will not need things like `assoc-predicate'. > > map.el could require cl-lib and use cl-assoc? Actually, it already does require cl-lib, because the following chain: * map.el requires `seq' * seq.el requires `cl-lib' Indeed, in my patch `assoc-predicate' doesn't appear in map.el, so it's not just a matter of replace: assoc-predicate ---> cl-assoc `assoc-predicate' appears in the implementation (subr.el) and setter expansion (gv.el) of `alist-get'. Neither subr.el nor gv.el are requiring `cl-lib'. From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 07:06:26 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 11:06:26 +0000 Received: from localhost ([127.0.0.1]:54276 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT4c6-0007DP-A6 for submit@debbugs.gnu.org; Thu, 06 Jul 2017 07:06:26 -0400 Received: from petton.fr ([89.234.186.68]:50784) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT4c4-0007DC-TL for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 07:06:25 -0400 From: Nicolas Petton To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <87van56h6b.fsf@petton.fr> Date: Thu, 06 Jul 2017 13:06:14 +0200 Message-ID: <87lgo16d09.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499339177; bh=8tIvg4a3oSGB71YXrvQJoKilvpt0nRi2LVZYsdTm5kg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=T48uPAMwUiSLg3q2z3SJ5BiWsJskqGO+NssG0rYW6j8YGtsT1iYYL5PJBeDvrYAA0DijCuMGBt4uQN/U/VK1Q1yCME13YrhaZm0848kggqO90WEsVgA4IVXxPGRKJJVvis2Czhmw1iD+FvdPse1PPrH+dJdjKDiAZLep4uyesFs= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Stefan Monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: > `assoc-predicate' appears in the implementation (subr.el) > and setter expansion (gv.el) of `alist-get'. > > Neither subr.el nor gv.el are requiring `cl-lib'. Oh, right, indeed. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZXhmmAAoJECM1h6R8IHkQpVgIALvmVjJxvADbqsTjd9FtOPwZ LNgqL1p65AqtOXZry+KL9bWNbT/TUXEUgPPYJn+KuDKYNHPcyNlTKe9AKJ0j6i+l Zm5/ENVRUyfUQhFqZRg3DkaHDCEKORhccD30D7k/vQDGu/AytBUz9DVFabuSdOdq 825YUWSMTDzs9IKR2IVwXs6zR4l2M6AXKwZKXoykY7jPRsiXBjsUyAaw9R05WkJZ ljSL1GQGMMm4251z5zAOZKE141RfdPKQ2SSRLJ45KgXRSuwIRUh9udn0eBF1Napz E7Eb0kUKKGW4yAALEtUhUQacFnYU8mhb40LT2fxZhIhDLrn5jeI+/qLhCMwdztE= =qwU5 -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 10:57:12 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 14:57:12 +0000 Received: from localhost ([127.0.0.1]:55270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT8DQ-0005xB-HX for submit@debbugs.gnu.org; Thu, 06 Jul 2017 10:57:12 -0400 Received: from petton.fr ([89.234.186.68]:34288) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT8DN-0005ww-MD for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 10:57:10 -0400 From: Nicolas Petton To: Tino Calancha , 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87y3s2m76v.fsf@calancha-pc> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> Date: Thu, 06 Jul 2017 16:56:59 +0200 Message-ID: <8760f562bo.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499353023; bh=StAMUhKiht69k9vA6k/XiTqvtmUS79HXf55Y6szohF4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=S1wHEeH0v8kPjsivP7uekMV8YDHVKq/UdYCTaAJ9eWmecTAXSXvrnF4fePHJg4IZw8mAk2HO95MA+b1nfqUs3vrmQU9XmIPO8/TK66RcsGy0Ff0MZluc0N3V6saKGDa2LhG9Rimket2dIugO4qn2EQxYjszC67G8gXypad9lxzE= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: > 1. In my patch `assoc-predicate' is a defsubst. > Should does exit at all? I would inline its call and use `assoc-default' directly, but I guess it's a matter of taste. But wouldn't it be better if `assoc' took an optional testfn? I'm not sure I like the `full' parameter in `assoc-default', and I think the inconsistency of the return values between `assoc' and `assoc-default' is already confusing. Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZXk+7AAoJECM1h6R8IHkQt6sH/iw2a+vKxvJHQmxluHuV+HIg Ctbkiw01eSIDCze4G7EtPFk3Up11A2fp+lRv3ctK2hf13bJA7ilk5yY9d0XRmK0b FfXS+L8NT0BRbNpJYlJwD9ZC7M+xy+VxC3YCe4pBT/30bdQmuvSk93c1BoDcFjEZ pI02lpfPG+XFgk/FnKHn/rTgmT8nNrBmoS0QRh0g38ZLm9HwSK9wKlPiZbZV279Z 3Z7Er57mpgoqpN1zYoBg1iMcnuEKXVQaBrFhLSYGwYSouRdjpBG8gtjVPq4g89de jUW+rGRpH3cmkO31AE9cSli/pRGNPrImY4MKWk7g1K3pxh0TXes3CdmLXp/g6rs= =5ulM -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 06 11:07:18 2017 Received: (at 27584) by debbugs.gnu.org; 6 Jul 2017 15:07:18 +0000 Received: from localhost ([127.0.0.1]:55276 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT8NC-0006C3-FS for submit@debbugs.gnu.org; Thu, 06 Jul 2017 11:07:18 -0400 Received: from pruche.dit.umontreal.ca ([132.204.246.22]:34118) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dT8NA-0006Bv-G9 for 27584@debbugs.gnu.org; Thu, 06 Jul 2017 11:07:17 -0400 Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id v66F7Ew1000654; Thu, 6 Jul 2017 11:07:14 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 08F3B66273; Thu, 6 Jul 2017 11:07:14 -0400 (EDT) From: Stefan Monnier To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> Date: Thu, 06 Jul 2017 11:07:14 -0400 In-Reply-To: (Tino Calancha's message of "Thu, 6 Jul 2017 15:20:49 +0900 (JST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6065=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6065> : inlines <5969> : streams <1753027> : uri <2457317> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) >>> 1. In my patch `assoc-predicate' is a defsubst. >>> Should does exit at all? >>> If yes: >>> *) should be a defun instead? >>> **) should be named `assoc-predicate' or differently? >> It's been called cl-assoc so far ;-) > Some day your dream will be fulfilled, and `cl-lib' will be preloaded at > startup. I'm not sure it's my dream, to tell you the truth: I like Scheme's choice of not treating "keyword symbols" specially, so macros can use them (because the keyword args aren't evaluated), but not functions. This ensures that the cost of keyword-argument parsing is only paid during macro expansion (where it's tolerable) but not at run-time (where it's much too costly and hence absolutely requires compiler-macro crutches). > Then, we will not need things like `assoc-predicate'. In reality, my intention, beside putting a smiley, was to point you to another implementation which uses defun with a compiler-macro instead of defsubst. Actually your assoc-predicate might be a good candidate for define-inline (which is in dire need of documentation. I can't believe its author still hasn't bothered to put even a docstring). Something like (define-inline assoc-predicate (elem list &optional pred) (inline-letevals (elem list pred) (pcase (inline-const-val pred) ('eq (inline-quote (assq ,elem ,list))) ((or 'equal 'nil) (inline-quote (assoc ,elem ,list))) (_ (inline-quote (assoc-default ,elem ,list ,pred nil 'full)))))) -- Stefan From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 02:39:49 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 06:39:49 +0000 Received: from localhost ([127.0.0.1]:55686 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTMvc-0005is-TD for submit@debbugs.gnu.org; Fri, 07 Jul 2017 02:39:49 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTMvZ-0005if-QS for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 02:39:47 -0400 Received: by mail-pf0-f170.google.com with SMTP id q86so12472013pfl.3 for <27584@debbugs.gnu.org>; Thu, 06 Jul 2017 23:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=h7m1rmKMQTRyZAbqIfTcEeMCQxAdWo4cgdbXU8AUIGA=; b=GLuSFQS4Q5cRUY41J3Ry4HyVpG8dc15LhWiwE56AFBiNUE0KF6UoFEJV3XKTNj8tqf mpo7abeOHl/IeCJrRQ4k4qONImRsf6kzIiMFvv6MWzr+q6+HeRzGHwHoc76fToIZ/G9m PEeZOvXVyl1vRmwfhKRWqzBO7osutiOYhLcFtiX7LKlo8L41mOx3cbQ29B48dJK32eUk OB6GXnDlpO30t6mce/sjYxbIRuii5+z7B4G70IBwng2qguCgwWU+CBZ+mBzXUp4hch0L J9OQoOgykmT1O7XE8TyPHWPLZz2Z4hDVbdb4rEzrJ7yfsE7O4Shqidb7x62uN/qOMXTm nF4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=h7m1rmKMQTRyZAbqIfTcEeMCQxAdWo4cgdbXU8AUIGA=; b=ffwKsAGGiKdTq8yRKDJeSZoz7twHt2pizvUfQACpmPQX1LaShW5q7kIm0npK55K6ba 4/rfnpUsZ3U6nbGgSgtVmkCQ/Z3oexHx+ELwIeysEcO4jun358ZGi8tt7c++vRnDS9Jh wQoEGbtcUHJEv+bLoL/aVMA8MuXvgqtMnZL3lmLdpgCq51mH+cT1MzOMfyhLDKZakcfD rj5lyFZwhQCwW2zL7dtwQ26trM8bh6N4OypabtwKN8PSl30fdxEf0jXFreSifl2KOWmw F93kA7sKoSkRSwfVmeCuk6Be/TQP4AIEuAad++zFCRHSy6cLKeL57FrL0aCpba6yFGmj 6f0A== X-Gm-Message-State: AIVw110jOh4rrXkF3QtQ9UjxL67dCzL341sc32i5rJRmERaiFAUuEfn3 hENYiuc8V6pXKQ== X-Received: by 10.84.224.134 with SMTP id s6mr1202501plj.263.1499409579622; Thu, 06 Jul 2017 23:39:39 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id 22sm4672579pgb.23.2017.07.06.23.39.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Jul 2017 23:39:38 -0700 (PDT) From: Tino Calancha To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> Date: Fri, 07 Jul 2017 15:39:18 +0900 In-Reply-To: <8760f562bo.fsf@petton.fr> (Nicolas Petton's message of "Thu, 06 Jul 2017 16:56:59 +0200") Message-ID: <877ezk3g4p.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) Nicolas Petton writes: > Tino Calancha writes: > > >> 1. In my patch `assoc-predicate' is a defsubst. >> Should does exit at all? > > I would inline its call and use `assoc-default' directly, but I guess > it's a matter of taste. Following Stefan suggestion, we can optimize using a compiler macro. Then, `assoc-default' is just the default case. > > But wouldn't it be better if `assoc' took an optional testfn? I'm not > sure I like the `full' parameter in `assoc-default', and I think the > inconsistency of the return values between `assoc' and `assoc-default' > is already confusing. In fact, that would kill 2 birds in a shot. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 02:48:13 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 06:48:13 +0000 Received: from localhost ([127.0.0.1]:55692 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTN3k-0005wB-PD for submit@debbugs.gnu.org; Fri, 07 Jul 2017 02:48:13 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTN3j-0005vv-6g for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 02:48:12 -0400 Received: by mail-pf0-f193.google.com with SMTP id c24so3356013pfe.1 for <27584@debbugs.gnu.org>; Thu, 06 Jul 2017 23:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=bZFUAGIh1fnDFjL74VJKSYTntj00wiE0zSYnudBdaqY=; b=ejvGxxDNEgvA8H7fQDLmJ1qISfAqJvK0bfq5adQuKH4jlOZZrVERE0xz3MufYF2o78 8J4d8mzRD/JaL0qaCgcCIebP8R6GFzBV0MDMjzbfRDQSa0PTIp3VAhvgA1O5Gr/g/Flg MVBcPSP6hd2ZclhvdfvPA1LbIqTAIDQRs57peU0ZqJRD+TZyQ8cSNTeARxQM31ry8/ld Ook8y3v/5N0Vd3m7pDG9eQmP7enVb5CemKfqRQigIthJOG4LOf+LOrPgyVWeQopiWqYv 1SI0gj0EzoaoLbVXgdcYHiCO9BA3hFyZKqkmzLUWqPmXwBYLxMyXWlHJIo6wmU1kf0Qh +tyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=bZFUAGIh1fnDFjL74VJKSYTntj00wiE0zSYnudBdaqY=; b=pcHhr3GMscF706aQ4TWace4ZgxEUFC5PpSRMFQgQqgzSh4VgKR9YI7nmBY5PGUEFg/ 3ZcWtpMN6rpbbHCJue5PW0/G2yQiuav8IXls9VTDy4lrhXcLazJzp8Ct7R3jcqCti0mm xg5X9rDAqQyc3kw+JDkadlXcjwWRQyJLilcUrrQ1NPTGGbMjgo7BPKmCGqhCb2wurtmn qgkT++RTq7BVsCTvIV8S+aXR4Feeij3nzCeVDuThuvnOX8RtDNKoO0tNSMV4E/1EdP2L KQAwNbVMIHC+/1ENKh+Dv3uiLcJbiWvMTFqbr0WyJLwFbmHrRbtaDIZdQeirxkTQ6vjW dJUw== X-Gm-Message-State: AIVw110Fm31IW9POy2CkT407icvzznZIBUIRELBxq/88QSHQaaWYFQrw 1zeFKTCAHIwLgg== X-Received: by 10.84.224.74 with SMTP id a10mr1330156plt.210.1499410085064; Thu, 06 Jul 2017 23:48:05 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id h184sm3212025pge.66.2017.07.06.23.48.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Jul 2017 23:48:04 -0700 (PDT) From: Tino Calancha To: 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> Date: Fri, 07 Jul 2017 15:48:01 +0900 In-Reply-To: (Stefan Monnier's message of "Thu, 06 Jul 2017 11:07:14 -0400") Message-ID: <8737a83fq6.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Stefan Monnier writes: >>>> **) should be named `assoc-predicate' or differently? >>> It's been called cl-assoc so far ;-) >> Some day your dream will be fulfilled, and `cl-lib' will be preloaded at >> startup. > > I'm not sure it's my dream, to tell you the truth: I like Scheme's > choice of not treating "keyword symbols" specially, so macros can use > them (because the keyword args aren't evaluated), but not functions. > This ensures that the cost of keyword-argument parsing is only paid > during macro expansion (where it's tolerable) but not at run-time > (where it's much too costly and hence absolutely requires > compiler-macro crutches). thanks for th explanations. I see your point now. >> Then, we will not need things like `assoc-predicate'. > > In reality, my intention, beside putting a smiley, was to point you to another > implementation which uses defun with a compiler-macro instead of > defsubst. Actually your assoc-predicate might be a good candidate for > define-inline (which is in dire need of documentation. I can't believe > its author still hasn't bothered to put even a docstring). > > Something like > > (define-inline assoc-predicate (elem list &optional pred) > (inline-letevals (elem list pred) > (pcase (inline-const-val pred) > ('eq (inline-quote (assq ,elem ,list))) > ((or 'equal 'nil) (inline-quote (assoc ,elem ,list))) > (_ (inline-quote (assoc-default ,elem ,list ,pred nil 'full)))))) Yes, that sounds much better! I adapted your example into subr.el after stole from `cl--compiler-macro-assoc' another optimization. (See updated patch below) Nico, one thing worries me is the following: * After this patch, `map.el' v1.2 depends on Emacs version > 25: * because it makes a call to `alist-get' with 5 parameters i.e., it uses TESTFN. Is that a problem? --8<-----------------------------cut here---------------start------------->8--- commit b4855d2d641b9fe4e6a49e898f797c40fe872281 Author: Tino Calancha Date: Fri Jul 7 15:29:15 2017 +0900 alist-get: Add optional arg TESTFN If TESTFN is non-nil, then it is the predicate to lookup the alist. Otherwise, use 'eq' (Bug#27584). * lisp/subr.el (assoc-default): Add optional arg FULL. (alist-get) * lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN. * lisp/emacs-lisp/gv.el (alist-get): Update expander. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the changes. * test/lisp/emacs-lisp/map-tests.el (test-map-put-testfn-alist) (test-map-elt-testfn): New tests. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 8eab2818f9..d2ae3028d8 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,10 +1589,14 @@ Association Lists @end smallexample @end defun -@defun alist-get key alist &optional default remove -This function is like @code{assq}, but instead of returning the entire +@defun alist-get key alist &optional default remove testfn +This function is like @code{assq} when @var{testfn} is @code{nil}, +but instead of returning the entire association for @var{key} in @var{alist}, @w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}. +When @var{testfn} is non-@code{nil}, it returns @var{value} if @var{key} +is equal to the car of an element of @var{alist}. The equality is +tested with @var{testfn}. If @var{key} is not found in @var{alist}, it returns @var{default}. This is a generalized variable (@pxref{Generalized Variables}) that @@ -1640,7 +1644,7 @@ Association Lists @end smallexample @end defun -@defun assoc-default key alist &optional test default +@defun assoc-default key alist &optional test default full This function searches @var{alist} for a match for @var{key}. For each element of @var{alist}, it compares the element (if it is an atom) or the element's @sc{car} (if it is a cons) against @var{key}, by calling @@ -1652,7 +1656,8 @@ Association Lists If an alist element matches @var{key} by this criterion, then @code{assoc-default} returns a value based on this element. -If the element is a cons, then the value is the element's @sc{cdr}. +If the element is a cons, then the value is the element if @var{full} +is non-@code{nil}, or the element's @sc{cdr} if @var{full} is @code{nil}. Otherwise, the return value is @var{default}. If no alist element matches @var{key}, @code{assoc-default} returns diff --git a/etc/NEWS b/etc/NEWS index 13805ce0da..a395ac7aec 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1050,6 +1050,13 @@ break. * Lisp Changes in Emacs 26.1 ++++ +** New optional argument FULL in 'assoc-default', to return the full +matching element. + ++++ +** New optional argument TESTFN in 'alist-get', 'map-elt' and 'map-put'. + ** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index c5c12a6414..166881a458 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -377,10 +377,12 @@ setf `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) (gv-define-expander alist-get - (lambda (do key alist &optional default remove) + (lambda (do key alist &optional default remove testfn) (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist - (macroexp-let2 nil p `(assq ,k ,getter) + (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) + (assoc-default ,k ,getter ,testfn nil 'full) + (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) (lambda (v) diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index a89457e877..e25502d76f 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; Keywords: convenience, map, hash-table, alist, array -;; Version: 1.1 +;; Version: 1.2 ;; Package: map ;; Maintainer: emacs-devel@gnu.org @@ -93,11 +93,11 @@ map-let ((arrayp ,map-var) ,(plist-get args :array)) (t (error "Unsupported map: %s" ,map-var))))) -(defun map-elt (map key &optional default) +(defun map-elt (map key &optional default testfn) "Lookup KEY in MAP and return its associated value. If KEY is not found, return DEFAULT which defaults to nil. -If MAP is a list, `eql' is used to lookup KEY. +If MAP is a list, TESTFN is used to lookup KEY if non-nil or `eql' if nil. MAP can be a list, hash-table or array." (declare @@ -106,30 +106,31 @@ map-elt (gv-letplace (mgetter msetter) `(gv-delay-error ,map) (macroexp-let2* nil ;; Eval them once and for all in the right order. - ((key key) (default default)) + ((key key) (default default) (testfn testfn)) `(if (listp ,mgetter) ;; Special case the alist case, since it can't be handled by the ;; map--put function. ,(gv-get `(alist-get ,key (gv-synthetic-place ,mgetter ,msetter) - ,default) + ,default nil ,testfn) do) ,(funcall do `(map-elt ,mgetter ,key ,default) (lambda (v) `(map--put ,mgetter ,key ,v))))))))) (map--dispatch map - :list (alist-get key map default) + :list (alist-get key map default nil testfn) :hash-table (gethash key map default) :array (if (and (>= key 0) (< key (seq-length map))) (seq-elt map key) default))) -(defmacro map-put (map key value) +(defmacro map-put (map key value &optional testfn) "Associate KEY with VALUE in MAP and return VALUE. If KEY is already present in MAP, replace the associated value with VALUE. +When MAP is a list, test equality with TESTFN if non-nil, otherwise use `eql'. MAP can be a list, hash-table or array." - `(setf (map-elt ,map ,key) ,value)) + `(setf (map-elt ,map ,key nil ,testfn) ,value)) (defun map-delete (map key) "Delete KEY from MAP and return MAP. diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166..01c6c1628f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -650,23 +650,27 @@ copy-tree ;;;; Various list-search functions. -(defun assoc-default (key alist &optional test default) +(defun assoc-default (key alist &optional test default full) "Find object KEY in a pseudo-alist ALIST. ALIST is a list of conses or objects. Each element (or the element's car, if it is a cons) is compared with KEY by calling TEST, with two arguments: (i) the element or its car, and (ii) KEY. If that is non-nil, the element matches; then `assoc-default' - returns the element's cdr, if it is a cons, or DEFAULT if the - element is not a cons. + returns the element, if it is a cons and FULL is non-nil, + or the element's cdr, if it is a cons and FULL is nil, + or DEFAULT if the element is not a cons. If no element matches, the value is nil. If TEST is omitted or nil, `equal' is used." (let (found (tail alist) value) (while (and tail (not found)) (let ((elt (car tail))) - (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) - (setq found t value (if (consp elt) (cdr elt) default)))) + (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) + (setq found t + value (cond ((consp elt) + (if full elt (cdr elt))) + (t default))))) (setq tail (cdr tail))) value)) @@ -725,15 +729,18 @@ rassq-delete-all (setq tail tail-cdr)))) alist) -(defun alist-get (key alist &optional default remove) - "Return the value associated with KEY in ALIST, using `assq'. +(defun alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. This is a generalized variable suitable for use with `setf'. When using it to set a value, optional argument REMOVE non-nil means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. - (let ((x (assq key alist))) + (let ((x (if (and testfn (not (eq testfn 'eq))) + (assoc-default key alist testfn nil 'full) + (assq key alist)))) (if x (cdr x) default))) (defun remove (elt seq) diff --git a/test/lisp/emacs-lisp/map-tests.el b/test/lisp/emacs-lisp/map-tests.el index 07e85cc539..15b0655040 100644 --- a/test/lisp/emacs-lisp/map-tests.el +++ b/test/lisp/emacs-lisp/map-tests.el @@ -63,6 +63,11 @@ with-maps-do (with-maps-do map (should (= 5 (map-elt map 7 5))))) +(ert-deftest test-map-elt-testfn () + (let ((map (list (cons "a" 1) (cons "b" 2)))) + (should-not (map-elt map "a")) + (should (map-elt map "a" nil 'equal)))) + (ert-deftest test-map-elt-with-nil-value () (should (null (map-elt '((a . 1) (b)) @@ -94,6 +99,13 @@ with-maps-do (should (eq (map-elt alist 2) 'b)))) +(ert-deftest test-map-put-testfn-alist () + (let ((alist (list (cons "a" 1) (cons "b" 2)))) + (map-put alist "a" 3 'equal) + (should-not (cddr alist)) + (map-put alist "a" 9) + (should (cddr alist)))) + (ert-deftest test-map-put-return-value () (let ((ht (make-hash-table))) (should (eq (map-put ht 'a 'hello) 'hello)))) commit 536e4cf1dd8df61edb4bbc580ba1da787ba57f43 Author: Tino Calancha Date: Fri Jul 7 15:31:15 2017 +0900 assoc-predicate: New defun Add new function like 'assoc' with an optional arg PRED, a predicate to compare the elements in the alist. * lisp/subr.el (assoc-predicate): New defun. (alist-get): * lisp/emacs-lisp/gv.el (alist-get): Use it. * test/lisp/subr-tests.el (subr-assoc-default, subr-assoc-predicate): New tests. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the feature. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index d2ae3028d8..b2a0b2df09 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,6 +1589,25 @@ Association Lists @end smallexample @end defun +@defun assoc-predicate key alist &optional pred +This function is like @code{assoc} in that it returns the first +association for @var{key} in @var{alist}, but if @code{pred} is +non-@code{nil}, then it makes the comparison using @code{pred} +instead of @code{equal}. @code{assoc-predicate} returns @code{nil} +if no association in @var{alist} has a @sc{car}, @var{x}, satisfying +@code{(funcall pred x key)}. + +@smallexample +(setq leaves + '(("simple leaves" . oak) + ("compound leaves" . horsechestnut))) + +(assoc-predicate "simple leaves" leaves 'string=) + @result{} ("simple leaves" . oak) +@end smallexample + +@end defun + @defun alist-get key alist &optional default remove testfn This function is like @code{assq} when @var{testfn} is @code{nil}, but instead of returning the entire diff --git a/etc/NEWS b/etc/NEWS index a395ac7aec..e988186b6c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1050,6 +1050,11 @@ break. * Lisp Changes in Emacs 26.1 + ++++ +** New defun 'assoc-predicate', like 'assoc' with an optional argument +PRED, a predicate to compare the elements in the alist. + +++ ** New optional argument FULL in 'assoc-default', to return the full matching element. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 166881a458..29b85e280e 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -381,7 +381,7 @@ setf (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) - (assoc-default ,k ,getter ,testfn nil 'full) + (assoc-predicate ,k ,getter ,testfn) (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) diff --git a/lisp/subr.el b/lisp/subr.el index 01c6c1628f..80b10a62c0 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -674,6 +674,19 @@ assoc-default (setq tail (cdr tail))) value)) +(defun assoc-predicate (key alist &optional pred) + "Like `assoc' but compare keys with TEST." + (declare (compiler-macro + (lambda (_) + `(pcase ,pred + ('eq (assq ,key ,alist)) + ((or 'equal 'nil) (assoc ,key ,alist)) + ((guard (and (macroexp-const-p ,key) (eq ,pred 'eql))) + (if (floatp ,key) + (assoc ,key ,alist) (assq ,key ,alist))) + (_ (assoc-default ,key ,alist ,pred nil 'full)))))) + (assoc-default key alist pred nil 'full)) + (defun assoc-ignore-case (key alist) "Like `assoc', but ignores differences in case and text representation. KEY must be a string. Upper-case and lower-case letters are treated as equal. @@ -739,7 +752,7 @@ alist-get means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. (let ((x (if (and testfn (not (eq testfn 'eq))) - (assoc-default key alist testfn nil 'full) + (assoc-predicate key alist testfn) (assq key alist)))) (if x (cdr x) default))) diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 54f4ab5d1b..ab806f74c3 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -325,6 +325,23 @@ subr-tests--this-file (setq res (read-passwd "pass: " 'confirm (mapconcat #'string default ""))) (should (string= default res))))) +(ert-deftest subr-assoc-default () + (let ((alist (list (cons "a" 1) (cons "b" 2) "c"))) + (should (assoc-default "b" alist)) + (should-not (assoc-default "b" alist 'eq)) + (should-not (assoc-default "c" alist 'eq 'foo)) + ;; Return 4th argument if the found element is an atom. + (should (equal 'foo (assoc-default "c" alist 'equal 'foo))) + (should (equal 2 (assoc-default "b" alist 'equal nil))) + (should (equal '("b" . 2) (assoc-default "b" alist 'equal nil 'full))))) + +(ert-deftest subr-assoc-predicate () + (let ((alist (list (cons "a" 1) (cons "b" 2) "c"))) + (should (assoc-predicate "b" alist)) + (should-not (assoc-predicate "b" alist 'eq)) + (should-not (assoc-predicate "c" alist 'eq)) + (should-not (assoc-predicate "c" alist 'equal)) + (should (equal '("b" . 2) (assoc-predicate "b" alist 'equal))))) (provide 'subr-tests) ;;; subr-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-07 Repository revision: 51275358e91d654e0cb49b749bf83d2fa19476c7 From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 03:47:30 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 07:47:30 +0000 Received: from localhost ([127.0.0.1]:55708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTNz8-0007Jz-8p for submit@debbugs.gnu.org; Fri, 07 Jul 2017 03:47:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43177) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTNz6-0007Jm-A2 for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 03:47:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTNyx-0002By-VO for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 03:47:23 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTNyo-00029J-Ay; Fri, 07 Jul 2017 03:47:10 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:4076 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dTNym-0004m2-8Z; Fri, 07 Jul 2017 03:47:09 -0400 Date: Fri, 07 Jul 2017 10:46:55 +0300 Message-Id: <838tk0n0y8.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: <8737a83fq6.fsf@calancha-pc> (message from Tino Calancha on Fri, 07 Jul 2017 15:48:01 +0900) Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 27584 Cc: nicolas@petton.fr, 27584@debbugs.gnu.org, monnier@IRO.UMontreal.CA X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Tino Calancha > Date: Fri, 07 Jul 2017 15:48:01 +0900 > Cc: Nicolas Petton , > Stefan Monnier Thanks. A few comments about the documentation parts: > -@defun alist-get key alist &optional default remove > -This function is like @code{assq}, but instead of returning the entire > +@defun alist-get key alist &optional default remove testfn > +This function is like @code{assq} when @var{testfn} is @code{nil}, > +but instead of returning the entire > association for @var{key} in @var{alist}, > @w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}. > +When @var{testfn} is non-@code{nil}, it returns @var{value} if @var{key} > +is equal to the car of an element of @var{alist}. The equality is > +tested with @var{testfn}. > If @var{key} is not found in @var{alist}, it returns @var{default}. Sometimes, trying to make small changes to existing documentation makes the documentation less readable and even confusing. This is one of those cases: where previously alist-get was only a minor deviation from assq, and thus just mentioning those deviations would do, now the deviations are much more significant, and the reference to assq gets in the way instead of helping. So I would rewrite the documentation like this: @defun alist-get key alist &optional default remove testfn This function is similar to @code{assq}. It finds the first association @w{@code{(@var{key} . @var{value})}} by comparing @var{key} with @var{alist} elements, and, if found, returns the @var{value} of that association. If no association is found, the function returns @var{default}. Comparison of @var{key} against @var{alist} elements uses the function specified by @var{testfn}, defaulting to @code{eq}. The return value is a generalized variable (@pxref{Generalized Variables}) that can be used to change a value with @code{setf}. When using it to set a value, optional argument @var{remove} non-@code{nil} means to remove @var{key}'s association from @var{alist} if the new value is @code{eql} to @var{default}. @end defun > -@defun assoc-default key alist &optional test default > +@defun assoc-default key alist &optional test default full > This function searches @var{alist} for a match for @var{key}. For each > element of @var{alist}, it compares the element (if it is an atom) or > the element's @sc{car} (if it is a cons) against @var{key}, by calling > @@ -1652,7 +1656,8 @@ Association Lists > > If an alist element matches @var{key} by this criterion, > then @code{assoc-default} returns a value based on this element. > -If the element is a cons, then the value is the element's @sc{cdr}. > +If the element is a cons, then the value is the element if @var{full} > +is non-@code{nil}, or the element's @sc{cdr} if @var{full} is @code{nil}. Suggest to simplify: If the element is a cons, then the value is the element's @sc{cdr} if @var{full} is @code{nil} or omitted, or the entire element otherwise. > -(defun map-elt (map key &optional default) > +(defun map-elt (map key &optional default testfn) > "Lookup KEY in MAP and return its associated value. > If KEY is not found, return DEFAULT which defaults to nil. > > -If MAP is a list, `eql' is used to lookup KEY. > +If MAP is a list, TESTFN is used to lookup KEY if non-nil or `eql' if nil. Since the sentence references more than one argument, the "or `eql' if nil" part is ambiguous. Suggest to disambiguate: If MAP is a list, `eql' is used to lookup KEY. Optional argument TESTFN, if non-nil, means use its function definition instead of `eql'. > -(defmacro map-put (map key value) > +(defmacro map-put (map key value &optional testfn) > "Associate KEY with VALUE in MAP and return VALUE. > If KEY is already present in MAP, replace the associated value > with VALUE. > +When MAP is a list, test equality with TESTFN if non-nil, otherwise use `eql'. Likewise here. > -(defun assoc-default (key alist &optional test default) > +(defun assoc-default (key alist &optional test default full) > "Find object KEY in a pseudo-alist ALIST. > ALIST is a list of conses or objects. Each element > (or the element's car, if it is a cons) is compared with KEY by > calling TEST, with two arguments: (i) the element or its car, > and (ii) KEY. > If that is non-nil, the element matches; then `assoc-default' > - returns the element's cdr, if it is a cons, or DEFAULT if the > - element is not a cons. > + returns the element, if it is a cons and FULL is non-nil, > + or the element's cdr, if it is a cons and FULL is nil, ^^ That "it" is ambiguous: does it refer to "element" or to "cdr"? > -(defun alist-get (key alist &optional default remove) > - "Return the value associated with KEY in ALIST, using `assq'. > +(defun alist-get (key alist &optional default remove testfn) > + "Return the value associated with KEY in ALIST. > If KEY is not found in ALIST, return DEFAULT. > +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. Again, "if non-nil" is ambiguous: it could refer to TESTFN or to alist. > +@defun assoc-predicate key alist &optional pred > +This function is like @code{assoc} in that it returns the first > +association for @var{key} in @var{alist}, but if @code{pred} is > +non-@code{nil}, then it makes the comparison using @code{pred} > +instead of @code{equal}. @code{assoc-predicate} returns @code{nil} > +if no association in @var{alist} has a @sc{car}, @var{x}, satisfying > +@code{(funcall pred x key)}. ^^^^^^^^^^^^^^^^^^ "pred", "x", and "key" should be in @var here. I'd also include the entire @code snippet in @w{..}, so that it won't be split between two lines. > ++++ > +** New defun 'assoc-predicate', like 'assoc' with an optional argument > +PRED, a predicate to compare the elements in the alist. Please use "function" in NEWS, not "defun". > +(defun assoc-predicate (key alist &optional pred) > + "Like `assoc' but compare keys with TEST." ^^^^ PRED, not TEST. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 04:09:59 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 08:09:59 +0000 Received: from localhost ([127.0.0.1]:55712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOKt-0007oK-BR for submit@debbugs.gnu.org; Fri, 07 Jul 2017 04:09:59 -0400 Received: from petton.fr ([89.234.186.68]:58988) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOKr-0007o6-NB for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 04:09:58 -0400 From: Nicolas Petton To: Tino Calancha , 27584@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <8737a83fq6.fsf@calancha-pc> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> Date: Fri, 07 Jul 2017 10:09:50 +0200 Message-ID: <877ezkvfap.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499414991; bh=SsxQYpeehIhMJPxoE/hgTpv7nx5WarQe2JHE6S10oZM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=dgkMxfPivINWKciqgON2z+wrOZLTVqfDaF/OpVEUFYjZWfvDICRsfW4hk8L6N9ggxlUnqTSnT6vlyx+hKV+XUn6yE6hSRaVW2Yocs2ow7Z2x2a2Id2P6qvQjI+0SYZXmc4SNMrcmL8ROZFurUaZL3q8rn3wn/DOSRpDZZTvKbUQ= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: > Nico, one thing worries me is the following: > * After this patch, `map.el' v1.2 depends on Emacs version > 25: > * because it makes a call to `alist-get' with 5 parameters i.e., it > uses TESTFN. > Is that a problem? map.el is not distributed outside of Emacs, so it shouldn't be a problem. I plan to do a more or less complete rewrite of map.el based on the same design I used in the rewrite of seq.el (using methods for dispatching). Maybe then I'll distribute it in GNU ELPA as well, but that's something to worry about later, and we can always find solutions :) Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZX0HOAAoJECM1h6R8IHkQVJ4IAIfQ+EKUudjuYJD3dsJkdwTe eWQajkkN188wpCNvlCjikie7UO8j5/1NFYlbfKw9sb+JLf0QsfZJ+88O/1Cs5Rlr a/GHJhj+/VgnqEj+fXp0ibliPg6+afoS54JBglogBxeAtLOp/pBDaBKx2IeBGrHv UdFB47sJ+AfsL3w7pQBpJmlhJfgTFqV/ZyPAfC+tUg/oIFyZA7qrHzMa+UZw2gCc MByMAqu7XwIuhSbgz/YLsybp54eUTyDKDdICqVZtPplPMbNiPiJ0W1Xabal7h8ur poTzPJzTRBhW3i3barcSojq1vt8XOunCDcj/LEIOhW5s3ucY4aUXRshvWcWj6Zg= =lb4X -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 04:12:00 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 08:12:01 +0000 Received: from localhost ([127.0.0.1]:55716 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOMq-0007rY-NQ for submit@debbugs.gnu.org; Fri, 07 Jul 2017 04:12:00 -0400 Received: from petton.fr ([89.234.186.68]:59418) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOMp-0007rJ-LD for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 04:11:59 -0400 From: Nicolas Petton To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <877ezk3g4p.fsf@calancha-pc> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> Date: Fri, 07 Jul 2017 10:11:53 +0200 Message-ID: <874luovf7a.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499415114; bh=rX5Evpb/qoeMWrCaS34+WU/eyJP2Z4ZeCfervriqo98=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=onALW9pw08RnVoGE3ogHC22HEPWj7FpHvpKAASfiSKgU2jkkVzO3NakHLEAb57uZYqbMads9NNK3EqMy131jtXVVwnEu9z9xAO67khsAQVV15B6q9ussYyQoQmw9c6ECrN6KjbTQXU6LkseNEGTwZJwHC9wk81r3hKN1ujCjZ0k= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, stefan monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: >> But wouldn't it be better if `assoc' took an optional testfn? I'm not >> sure I like the `full' parameter in `assoc-default', and I think the >> inconsistency of the return values between `assoc' and `assoc-default' >> is already confusing. > In fact, that would kill 2 birds in a shot. I don't understand what you mean. Would it be a good thing to kill these 2 birds? :-D Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZX0JJAAoJECM1h6R8IHkQw4sIAIDDiQcSFnWIVZ3MTC3ryP5Y vGKupzxyxwup0qN/IdoktGNIFQtJg29RSeqsgHRF6xtmICFzTM9iCXmd/GG6nmFx C7PnmMZ8Wr6IZgC198VzP0f6exw+zroNA/pWjVXeDt1SFlB9IAeaszGeXQrURwAn jd2WLheMY0ufkHmuxAjtbwhBD66TW/9ehJti9x5dXsAhnIqSAqVFMi7L5eoxmsJ4 Bs34E4Io3xzoVd6WftX8uq6mL1gBOZuH2sKrGekLqH6F1VzlHlXQHfSoNM0rn14M URJ+ynZ34vULh6IBE1FI4fKLgAKP6QU028OYJnWyrr/fvzwlQTyP+YZ80asgsdY= =Rppb -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 04:22:51 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 08:22:52 +0000 Received: from localhost ([127.0.0.1]:55722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOXL-00086k-Pw for submit@debbugs.gnu.org; Fri, 07 Jul 2017 04:22:51 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOXJ-00086W-Lq for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 04:22:50 -0400 Received: by mail-pf0-f194.google.com with SMTP id c24so3649146pfe.1 for <27584@debbugs.gnu.org>; Fri, 07 Jul 2017 01:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=PurFxFkL/p71QgDwI0tFbcgefJeFnGfe2R4Z9JuASrg=; b=ODH0/xSXqxhx81+Hj1+BlAd4yCt4EuufFIGQCg2BPU9LCSGTv82/CCdCRi04fnWF2S wJlzwwlMZHcSQftMXgv3+uOYAziKkXduc4F0eheNZmP6yoJ+XSLKSZXeo3LZK/UUo+1+ U8MXxfeFb22F1UJnVj3uDmZv9LVv1a9eMR61Gx/1Ao8PHEAXrhBIV8S1fNOziWNvFSkN FBX+lUb7R4k0/ZpEMeoJOd7DRpfeFFNNrC8LV2vBaZDTzDDPi5b3p8h/koTpK/6ni9Tq ZGSdmKtCSbxg8fRqo8RTpbkGIoHde5sARPI4rzx2h+yPx/Nq9TvR1dd0rsvD0rb9KWBE Cn5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=PurFxFkL/p71QgDwI0tFbcgefJeFnGfe2R4Z9JuASrg=; b=CW9yeEb0PDzDGPzGqWiP/Wlnb9Ns8MhS+gj6PXeFZRoVsEWwsGmRzYGJO/doxnSbOU thSgugYUywwcC/FCWYDVwUzaPY/eXXlzYbMeTcRgUgZBwovJX7CbAAG1ki8ug+CdLwWq 1CUDLl69NB+e7fvbdm3Z8TVQgRsp45lwH958wnJ47selIgEKGDuto6o25uKXc6ZuierP uB+qNfY1hr9Ur1JQ6i4jk005W8HfnL0S+zx4bA/J4umyqbOu6qUHolGZo+DMIxhPFhSo bs4XWtJDiefRFVyn0AOLEs7x/4eIaad+h74Gmkf+SFuesIt51J+Iz6hPGtj+sPydQacC Xr9g== X-Gm-Message-State: AIVw113WrCltv8dz5A7exZGgzyXEYA+t5klkNCp4mMf6AP5ejROaW3JC k4L6gBRBFNxVjg== X-Received: by 10.98.96.66 with SMTP id u63mr4862928pfb.68.1499415763585; Fri, 07 Jul 2017 01:22:43 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id n13sm4469956pgs.0.2017.07.07.01.22.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jul 2017 01:22:43 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Fri, 7 Jul 2017 17:22:40 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <874luovf7a.fsf@petton.fr> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, stefan monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Fri, 7 Jul 2017, Nicolas Petton wrote: > Tino Calancha writes: > >>> But wouldn't it be better if `assoc' took an optional testfn? I'm not >>> sure I like the `full' parameter in `assoc-default', and I think the >>> inconsistency of the return values between `assoc' and `assoc-default' >>> is already confusing. > >> In fact, that would kill 2 birds in a shot. > > I don't understand what you mean. Would it be a good thing to > kill these 2 birds? :-D It depends if you like to eat birds. They are lighther than beef. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 04:34:53 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 08:34:53 +0000 Received: from localhost ([127.0.0.1]:55727 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOiy-0008PD-Rp for submit@debbugs.gnu.org; Fri, 07 Jul 2017 04:34:53 -0400 Received: from petton.fr ([89.234.186.68]:35990) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTOix-0008Oy-6b for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 04:34:51 -0400 From: Nicolas Petton To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> Date: Fri, 07 Jul 2017 10:34:44 +0200 Message-ID: <87shi8tzkr.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499416485; bh=014PCagkJHNnSmCOnAZzlsx6KjLw8rZ7kYKadmKGVAI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=OwTE/zC9qbjtX43/tDx6T1b1PzPp5yMwfz6tcOfSQSoog6MNUKmKlZbpsi3x1BIJQlDzrlC/JBfoDl4iQQ5ycKNLNReRtJqrAnhd9/iCq5FdThra/XTiKrvfEcOkBerAfG+qirxgs1CcyTrmhIklmHW1cQdFlDFgAoBbRvo0Rig= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, stefan monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: >> I don't understand what you mean. Would it be a good thing to >> kill these 2 birds? :-D > It depends if you like to eat birds. They are lighther than beef. Now I'll have to explain to puzzled people sitting next to me why I was laughing out loud while staring at my emails. More seriously, could you explain what you meant? Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZX0ekAAoJECM1h6R8IHkQGpMH/iTfmJrfq2JloZDI/tz3O7Pv V6k6yVzwZUJczwmfVKcRf/b9UiRVeJYrzU6SLHUrMhtxqpz6s037TjsjXv/OcSvL WQQBsGzFal51GzHUqZMqkpJLPDbONQkXI0WUYF0s9CEi1ONNsWADrzIbznCIEUow G3u4LjK9FdmFdXbIcNdBGXqtafnOpuqJ4OW2JrkAxTBYRk+jvuMeYwfhtocCzcQ2 osHyVnk2GYYhJyjlh9kLdVG+coq7SwB+YIlL3n/mpBulkbUibpOwLMZeFAiMduj9 dBTE0q/7Zbon6EmlAugDsj9XISyk7YxJozp9kTPBdN8tEvfrmgUBCLB/1nmw8ps= =GmM9 -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 11:49:52 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 15:49:52 +0000 Received: from localhost ([127.0.0.1]:56919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVVw-0003a6-4T for submit@debbugs.gnu.org; Fri, 07 Jul 2017 11:49:52 -0400 Received: from chene.dit.umontreal.ca ([132.204.246.20]:55655) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVVt-0003Zx-8I for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 11:49:50 -0400 Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id v67FnkIM006812; Fri, 7 Jul 2017 11:49:47 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 93BC266273; Fri, 7 Jul 2017 11:49:46 -0400 (EDT) From: Stefan Monnier To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> Date: Fri, 07 Jul 2017 11:49:46 -0400 In-Reply-To: <87shi8tzkr.fsf@petton.fr> (Nicolas Petton's message of "Fri, 07 Jul 2017 10:34:44 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.1 X-NAI-Spam-Rules: 3 Rules triggered GEN_SPAM_FEATRE=0.1, EDT_SA_DN_PASS=0, RV6066=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6066> : inlines <5972> : streams <1753174> : uri <2458036> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) > More seriously, could you explain what you meant? It's like "faire d'une pierre deux coups", which you could also relate to "buy one get one free". So, yes, it's a good thing to kill two birds in a shot. Stefan "damn birds!" From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 11:54:01 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 15:54:01 +0000 Received: from localhost ([127.0.0.1]:56924 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVZx-0003g5-Ko for submit@debbugs.gnu.org; Fri, 07 Jul 2017 11:54:01 -0400 Received: from pruche.dit.umontreal.ca ([132.204.246.22]:48878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVZw-0003fy-QK for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 11:54:01 -0400 Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id v67FrwBB002423; Fri, 7 Jul 2017 11:53:59 -0400 Received: by ceviche.home (Postfix, from userid 20848) id C8EC566273; Fri, 7 Jul 2017 11:53:58 -0400 (EDT) From: Stefan Monnier To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> Date: Fri, 07 Jul 2017 11:53:58 -0400 In-Reply-To: <8737a83fq6.fsf@calancha-pc> (Tino Calancha's message of "Fri, 07 Jul 2017 15:48:01 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6066=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6066> : inlines <5973> : streams <1753174> : uri <2458040> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) > + (declare (compiler-macro > + (lambda (_) > + `(pcase ,pred > + ('eq (assq ,key ,alist)) > + ((or 'equal 'nil) (assoc ,key ,alist)) > + ((guard (and (macroexp-const-p ,key) (eq ,pred 'eql))) > + (if (floatp ,key) > + (assoc ,key ,alist) (assq ,key ,alist))) > + (_ (assoc-default ,key ,alist ,pred nil 'full)))))) This replaces a call to the function with a chunk of code which does `pcase`, which is not what we want: we want the `pcase` to be executed during compilation and if we can't choose which branch to follow, then we just keep the call unchanged (which is why, in my define-inline example, the pcase was outside of `inline-quote`). Stefan From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 11:55:10 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 15:55:10 +0000 Received: from localhost ([127.0.0.1]:56928 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVb4-0003i6-0H for submit@debbugs.gnu.org; Fri, 07 Jul 2017 11:55:10 -0400 Received: from petton.fr ([89.234.186.68]:48266) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTVb1-0003hQ-8p for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 11:55:08 -0400 From: Nicolas Petton To: Stefan Monnier Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> Date: Fri, 07 Jul 2017 17:54:59 +0200 Message-ID: <87shi8s0mk.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499442901; bh=PV8FBU1UW7ASYoYM0drctc++7eBeaKWxRWqKyx1+MJA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=Wo5SKuUO4o7Gu625/IbRKAtlT8yaOx8NJtRclwEbG1AV3cji4BWq7bUjtPjI5VKJYYCMKjXP4xMKs7gAuqctp/8VoYHJ8j/qaov7V2y1OmiHTDg8wjFgyj0EguB/g2E8TUvu9kkFxZjPifBlbevp/7CsDPZlYz0Qb9Kin8c/yxU= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Stefan Monnier writes: > It's like "faire d'une pierre deux coups", which you could also relate > to "buy one get one free". So, yes, it's a good thing to kill two birds > in a shot. Thank you, it's all clear now :) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZX67TAAoJECM1h6R8IHkQoecH+gNNFcVyHZOBuy4LqJZrjaXJ hOZKoI92qmVTyphLpwjq6p828Ke6f/+zIDB/W8eqH0/1blBCNf8/Zn4jdHrlStOT 6mlJN4ZQdFm+6BHzZjGRQ0vCbT7g2Tx+ilYuqD9g2fB4C80jiru3jgEU6Twynz5Q SWp7ct0FzGldlVLhCZLhk+xaGNALKZSRBlwCPg94XWVlTLORVOdNlS1Q5BjlHpzX 3KGfrLA4yGo1MUAqfjY9pWYBmLyx7FUul/PNcnrUwNKhutxJWJWwS61y6zUkt4qR dc8+lp4JsSefBnQ0BTPeKZ9x5W+/HG15qWeFU4r0JSdwYNJGJFV+nor1z09EHBU= =Xy/Z -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 07 15:47:19 2017 Received: (at 27584) by debbugs.gnu.org; 7 Jul 2017 19:47:19 +0000 Received: from localhost ([127.0.0.1]:57096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTZDi-0002Sh-Iv for submit@debbugs.gnu.org; Fri, 07 Jul 2017 15:47:19 -0400 Received: from petton.fr ([89.234.186.68]:47512) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTZDg-0002ST-AS for 27584@debbugs.gnu.org; Fri, 07 Jul 2017 15:47:17 -0400 From: Nicolas Petton To: Stefan Monnier Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> Date: Fri, 07 Jul 2017 21:47:03 +0200 Message-ID: <8737a858so.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499456826; bh=pJk5/IPM6At2tGN7WxzxFSIZWyzMT+EBK+bX0axmRPg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=jAXJizbZ0kZVOPDQExoTWFZlTmcGxTd3chael1W4N7HGbjfeBFFwInFqpVOmapLo9pf68aFbQ/IuIRHvkOZypBBkfyXXF3doPZtZEsAUljrghq+PF3HzhkyO+K2dd2haPOJFxknEROuXwdsVyjUAEKJCdH2JttXp2REmXySapcE= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Stefan Monnier writes: > It's like "faire d'une pierre deux coups", which you could also relate > to "buy one get one free". So, yes, it's a good thing to kill two birds > in a shot. Now that I know it's a good things to kill birds, what about the patch below, and then applyind a modified version of your patch, Tino? From=200ac5e42962fde069680fefeddc3ab589fe4b6d6c Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Fri, 7 Jul 2017 21:21:55 +0200 Subject: [PATCH] Add an optional testfn parameter to assoc * src/fns.c (assoc): New optional testfn parameter used for comparison when provided. * test/src/fns-tests.el (test-assoc-testfn): Add tests for the new 'testfn' parameter. * src/buffer.c: * src/coding.c: * src/dbusbind.c: * src/font.c: * src/fontset.c: * src/gfilenotify.c: * src/image.c: * src/keymap.c: * src/process.c: * src/w32fns.c: * src/w32font.c: * src/w32notify.c: * src/w32term.c: * src/xdisp.c: * src/xfont.c: Add a third argument to Fassoc calls. * etc/NEWS: * doc/lispref/lists.texi: Document the new 'testfn' parameter. =2D-- doc/lispref/lists.texi | 18 +++++++++--------- etc/NEWS | 5 +++++ src/buffer.c | 2 +- src/coding.c | 6 +++--- src/dbusbind.c | 6 +++--- src/fns.c | 23 ++++++++++++++++------- src/font.c | 2 +- src/fontset.c | 2 +- src/gfilenotify.c | 2 +- src/image.c | 2 +- src/keymap.c | 2 +- src/process.c | 2 +- src/w32fns.c | 2 +- src/w32font.c | 2 +- src/w32notify.c | 4 ++-- src/w32term.c | 2 +- src/xdisp.c | 6 +++--- src/xfont.c | 3 ++- test/src/fns-tests.el | 6 ++++++ 19 files changed, 59 insertions(+), 38 deletions(-) diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 8eab281..966d8f1 100644 =2D-- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1511,12 +1511,12 @@ Association Lists each key can occur only once. @xref{Property Lists}, for a comparison of property lists and association lists. =20 =2D@defun assoc key alist +@defun assoc key alist &optional testfn This function returns the first association for @var{key} in @var{alist}, comparing @var{key} against the alist elements using =2D@code{equal} (@pxref{Equality Predicates}). It returns @code{nil} if no =2Dassociation in @var{alist} has a @sc{car} @code{equal} to @var{key}. =2DFor example: +@var{testfn} if non-nil, or @code{equal} if nil (@pxref{Equality +Predicates}). It returns @code{nil} if no association in @var{alist} +has a @sc{car} equal to @var{key}. For example: =20 @smallexample (setq trees '((pine . cones) (oak . acorns) (maple . seeds))) @@ -1561,11 +1561,11 @@ Association Lists @defun assq key alist This function is like @code{assoc} in that it returns the first association for @var{key} in @var{alist}, but it makes the comparison =2Dusing @code{eq} instead of @code{equal}. @code{assq} returns @code{nil} =2Dif no association in @var{alist} has a @sc{car} @code{eq} to @var{key}. =2DThis function is used more often than @code{assoc}, since @code{eq} is =2Dfaster than @code{equal} and most alists use symbols as keys. =2D@xref{Equality Predicates}. +using @code{eq}. @code{assq} returns @code{nil} if no association in +@var{alist} has a @sc{car} @code{eq} to @var{key}. This function is +used more often than @code{assoc}, since @code{eq} is faster than +@code{equal} and most alists use symbols as keys. @xref{Equality +Predicates}. =20 @smallexample (setq trees '((pine . cones) (oak . acorns) (maple . seeds))) diff --git a/etc/NEWS b/etc/NEWS index 13805ce..d7a6f29 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -100,6 +100,11 @@ required capabilities are found in terminfo. See the = FAQ node * Changes in Emacs 26.1 =20 ++++ +** The function 'assoc' now takes an optional third argument 'testfn'. +This argument, when non-nil, is used for comparison instead of +'equal'. + ** The variable 'emacs-version' no longer includes the build number. This is now stored separately in a new variable, 'emacs-build-number'. =20 diff --git a/src/buffer.c b/src/buffer.c index 80dbd33..bf49d61 100644 =2D-- a/src/buffer.c +++ b/src/buffer.c @@ -1164,7 +1164,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object= buffer) { /* Look in local_var_alist. */ struct Lisp_Buffer_Local_Value *blv =3D SYMBOL_BLV (sym); XSETSYMBOL (variable, sym); /* Update In case of aliasing. */ =2D result =3D Fassoc (variable, BVAR (buf, local_var_alist)); + result =3D Fassoc (variable, BVAR (buf, local_var_alist), Qnil); if (!NILP (result)) { if (blv->fwd) diff --git a/src/coding.c b/src/coding.c index 5682fc0..50ad206 100644 =2D-- a/src/coding.c +++ b/src/coding.c @@ -10539,7 +10539,7 @@ usage: (define-coding-system-internal ...) */) ASET (this_spec, 2, this_eol_type); Fputhash (this_name, this_spec, Vcoding_system_hash_table); Vcoding_system_list =3D Fcons (this_name, Vcoding_system_list); =2D val =3D Fassoc (Fsymbol_name (this_name), Vcoding_system_alist); + val =3D Fassoc (Fsymbol_name (this_name), Vcoding_system_alist, Qnil); if (NILP (val)) Vcoding_system_alist =3D Fcons (Fcons (Fsymbol_name (this_name), Qnil), @@ -10554,7 +10554,7 @@ usage: (define-coding-system-internal ...) */) =20 Fputhash (name, spec_vec, Vcoding_system_hash_table); Vcoding_system_list =3D Fcons (name, Vcoding_system_list); =2D val =3D Fassoc (Fsymbol_name (name), Vcoding_system_alist); + val =3D Fassoc (Fsymbol_name (name), Vcoding_system_alist, Qnil); if (NILP (val)) Vcoding_system_alist =3D Fcons (Fcons (Fsymbol_name (name), Qnil), Vcoding_system_alist); @@ -10662,7 +10662,7 @@ DEFUN ("define-coding-system-alias", Fdefine_coding= _system_alias, =20 Fputhash (alias, spec, Vcoding_system_hash_table); Vcoding_system_list =3D Fcons (alias, Vcoding_system_list); =2D val =3D Fassoc (Fsymbol_name (alias), Vcoding_system_alist); + val =3D Fassoc (Fsymbol_name (alias), Vcoding_system_alist, Qnil); if (NILP (val)) Vcoding_system_alist =3D Fcons (Fcons (Fsymbol_name (alias), Qnil), Vcoding_system_alist); diff --git a/src/dbusbind.c b/src/dbusbind.c index d2460fd..0d9d3e5 100644 =2D-- a/src/dbusbind.c +++ b/src/dbusbind.c @@ -955,7 +955,7 @@ xd_get_connection_address (Lisp_Object bus) DBusConnection *connection; Lisp_Object val; =20 =2D val =3D CDR_SAFE (Fassoc (bus, xd_registered_buses)); + val =3D CDR_SAFE (Fassoc (bus, xd_registered_buses, Qnil)); if (NILP (val)) XD_SIGNAL2 (build_string ("No connection to bus"), bus); else @@ -1057,7 +1057,7 @@ xd_close_bus (Lisp_Object bus) Lisp_Object busobj; =20 /* Check whether we are connected. */ =2D val =3D Fassoc (bus, xd_registered_buses); + val =3D Fassoc (bus, xd_registered_buses, Qnil); if (NILP (val)) return; =20 @@ -1127,7 +1127,7 @@ this connection to those buses. */) xd_close_bus (bus); =20 /* Check, whether we are still connected. */ =2D val =3D Fassoc (bus, xd_registered_buses); + val =3D Fassoc (bus, xd_registered_buses, Qnil); if (!NILP (val)) { connection =3D xd_get_connection_address (bus); diff --git a/src/fns.c b/src/fns.c index 6610d2a..6f4fb87 100644 =2D-- a/src/fns.c +++ b/src/fns.c @@ -1417,18 +1417,27 @@ assq_no_quit (Lisp_Object key, Lisp_Object list) return Qnil; } =20 =2DDEFUN ("assoc", Fassoc, Sassoc, 2, 2, 0, =2D doc: /* Return non-nil if KEY is `equal' to the car of an element= of LIST. =2DThe value is actually the first element of LIST whose car equals KEY. *= /) =2D (Lisp_Object key, Lisp_Object list) +DEFUN ("assoc", Fassoc, Sassoc, 2, 3, 0, + doc: /* Return non-nil if KEY is equal to the car of an element of = LIST. +The value is actually the first element of LIST whose car equals KEY. + +Equality is defined by TESTFN if non-nil or by `equal' if nil. */) + (Lisp_Object key, Lisp_Object list, Lisp_Object testfn) { Lisp_Object tail =3D list; FOR_EACH_TAIL (tail) { Lisp_Object car =3D XCAR (tail); =2D if (CONSP (car) =2D && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key)))) =2D return car; + if (NILP (testfn)) + { + if (CONSP (car) + && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key)))) + return car; + } + else if (CONSP (car) && (!NILP (call2 (testfn, (XCAR (car)), key)))) + { + return car; + } } CHECK_LIST_END (tail, list); return Qnil; diff --git a/src/font.c b/src/font.c index 5a3f271..a5e5b6a 100644 =2D-- a/src/font.c +++ b/src/font.c @@ -1893,7 +1893,7 @@ otf_tag_symbol (OTF_Tag tag) static OTF * otf_open (Lisp_Object file) { =2D Lisp_Object val =3D Fassoc (file, otf_list); + Lisp_Object val =3D Fassoc (file, otf_list, Qnil); OTF *otf; =20 if (! NILP (val)) diff --git a/src/fontset.c b/src/fontset.c index 850558b..7401806 100644 =2D-- a/src/fontset.c +++ b/src/fontset.c @@ -1186,7 +1186,7 @@ fs_query_fontset (Lisp_Object name, int name_pattern) { tem =3D Frassoc (name, Vfontset_alias_alist); if (NILP (tem)) =2D tem =3D Fassoc (name, Vfontset_alias_alist); + tem =3D Fassoc (name, Vfontset_alias_alist, Qnil); if (CONSP (tem) && STRINGP (XCAR (tem))) name =3D XCAR (tem); else if (name_pattern =3D=3D 0) diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 285a253..fa4854c 100644 =2D-- a/src/gfilenotify.c +++ b/src/gfilenotify.c @@ -266,7 +266,7 @@ reason. Removing the watch by calling `gfile-rm-watch'= also makes it invalid. */) (Lisp_Object watch_descriptor) { =2D Lisp_Object watch_object =3D Fassoc (watch_descriptor, watch_list); + Lisp_Object watch_object =3D Fassoc (watch_descriptor, watch_list, Qnil); if (NILP (watch_object)) return Qnil; else diff --git a/src/image.c b/src/image.c index 91749fb..1426e30 100644 =2D-- a/src/image.c +++ b/src/image.c @@ -4231,7 +4231,7 @@ xpm_load_image (struct frame *f, color_val =3D Qnil; if (!NILP (color_symbols) && !NILP (symbol_color)) { =2D Lisp_Object specified_color =3D Fassoc (symbol_color, color_symbols); + Lisp_Object specified_color =3D Fassoc (symbol_color, color_symbols, Qn= il); =20 if (CONSP (specified_color) && STRINGP (XCDR (specified_color))) { diff --git a/src/keymap.c b/src/keymap.c index b568f47..db9aa7c 100644 =2D-- a/src/keymap.c +++ b/src/keymap.c @@ -1292,7 +1292,7 @@ silly_event_symbol_error (Lisp_Object c) base =3D XCAR (parsed); name =3D Fsymbol_name (base); /* This alist includes elements such as ("RET" . "\\r"). */ =2D assoc =3D Fassoc (name, exclude_keys); + assoc =3D Fassoc (name, exclude_keys, Qnil); =20 if (! NILP (assoc)) { diff --git a/src/process.c b/src/process.c index abd017b..1900951 100644 =2D-- a/src/process.c +++ b/src/process.c @@ -951,7 +951,7 @@ DEFUN ("get-process", Fget_process, Sget_process, 1, 1,= 0, if (PROCESSP (name)) return name; CHECK_STRING (name); =2D return Fcdr (Fassoc (name, Vprocess_alist)); + return Fcdr (Fassoc (name, Vprocess_alist, Qnil)); } =20 /* This is how commands for the user decode process arguments. It diff --git a/src/w32fns.c b/src/w32fns.c index b0842b5..457599f 100644 =2D-- a/src/w32fns.c +++ b/src/w32fns.c @@ -467,7 +467,7 @@ if the entry is new. */) block_input (); =20 /* replace existing entry in w32-color-map or add new entry. */ =2D entry =3D Fassoc (name, Vw32_color_map); + entry =3D Fassoc (name, Vw32_color_map, Qnil); if (NILP (entry)) { entry =3D Fcons (name, rgb); diff --git a/src/w32font.c b/src/w32font.c index 67d2f6d..314d7ac 100644 =2D-- a/src/w32font.c +++ b/src/w32font.c @@ -1627,7 +1627,7 @@ x_to_w32_charset (char * lpcs) Format of each entry is (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). */ =2D this_entry =3D Fassoc (build_string (charset), Vw32_charset_info_alist= ); + this_entry =3D Fassoc (build_string (charset), Vw32_charset_info_alist, = Qnil); =20 if (NILP (this_entry)) { diff --git a/src/w32notify.c b/src/w32notify.c index 2520581..e8bdef8 100644 =2D-- a/src/w32notify.c +++ b/src/w32notify.c @@ -642,7 +642,7 @@ WATCH-DESCRIPTOR should be an object returned by `w32no= tify-add-watch'. */) /* Remove the watch object from watch list. Do this before freeing the object, do that even if we fail to free it, watch_list is kept free of junk. */ =2D watch_object =3D Fassoc (watch_descriptor, watch_list); + watch_object =3D Fassoc (watch_descriptor, watch_list, Qnil); if (!NILP (watch_object)) { watch_list =3D Fdelete (watch_object, watch_list); @@ -679,7 +679,7 @@ the watcher thread exits abnormally for any other reaso= n. Removing the watch by calling `w32notify-rm-watch' also makes it invalid. */) (Lisp_Object watch_descriptor) { =2D Lisp_Object watch_object =3D Fassoc (watch_descriptor, watch_list); + Lisp_Object watch_object =3D Fassoc (watch_descriptor, watch_list, Qnil); =20 if (!NILP (watch_object)) { diff --git a/src/w32term.c b/src/w32term.c index c37805c..0f7bb93 100644 =2D-- a/src/w32term.c +++ b/src/w32term.c @@ -6110,7 +6110,7 @@ x_calc_absolute_position (struct frame *f) =20 list =3D CDR(list); =20 =2D geometry =3D Fassoc (Qgeometry, attributes); + geometry =3D Fassoc (Qgeometry, attributes, Qnil); if (!NILP (geometry)) { monitor_left =3D Fnth (make_number (1), geometry); diff --git a/src/xdisp.c b/src/xdisp.c index 1c316fa..6717405 100644 =2D-- a/src/xdisp.c +++ b/src/xdisp.c @@ -22859,7 +22859,7 @@ display_mode_element (struct it *it, int depth, int= field_width, int precision, props =3D oprops; } =20 =2D aelt =3D Fassoc (elt, mode_line_proptrans_alist); + aelt =3D Fassoc (elt, mode_line_proptrans_alist, Qnil); if (! NILP (aelt) && !NILP (Fequal (props, XCDR (aelt)))) { /* AELT is what we want. Move it to the front @@ -28325,7 +28325,7 @@ set_frame_cursor_types (struct frame *f, Lisp_Objec= t arg) =20 /* By default, set up the blink-off state depending on the on-state. */ =20 =2D tem =3D Fassoc (arg, Vblink_cursor_alist); + tem =3D Fassoc (arg, Vblink_cursor_alist, Qnil); if (!NILP (tem)) { FRAME_BLINK_OFF_CURSOR (f) @@ -28463,7 +28463,7 @@ get_window_cursor_type (struct window *w, struct gl= yph *glyph, int *width, /* Cursor is blinked off, so determine how to "toggle" it. */ =20 /* First look for an entry matching the buffer's cursor-type in blink-cu= rsor-alist. */ =2D if ((alt_cursor =3D Fassoc (BVAR (b, cursor_type), Vblink_cursor_alist= ), !NILP (alt_cursor))) + if ((alt_cursor =3D Fassoc (BVAR (b, cursor_type), Vblink_cursor_alist, = Qnil), !NILP (alt_cursor))) return get_specified_cursor_type (XCDR (alt_cursor), width); =20 /* Then see if frame has specified a specific blink off cursor type. */ diff --git a/src/xfont.c b/src/xfont.c index b73596c..85fccf0 100644 =2D-- a/src/xfont.c +++ b/src/xfont.c @@ -505,7 +505,8 @@ xfont_list (struct frame *f, Lisp_Object spec) Lisp_Object alter; =20 if ((alter =3D Fassoc (SYMBOL_NAME (registry), =2D Vface_alternative_font_registry_alist), + Vface_alternative_font_registry_alist, + Qnil), CONSP (alter))) { /* Pointer to REGISTRY-ENCODING field. */ diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 2e46345..e294859 100644 =2D-- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -373,6 +373,12 @@ dot2 (should-error (assoc 3 d1) :type 'wrong-type-argument) (should-error (assoc 3 d2) :type 'wrong-type-argument))) =20 +(ert-deftest test-assoc-testfn () + (let ((alist '(("a" . 1) ("b" . 2)))) + (should-not (assoc "a" alist #'ignore)) + (should (eq (assoc "b" alist #'string-equal) (cadr alist))) + (should-not (assoc "b" alist #'eq)))) + (ert-deftest test-cycle-rassq () (let ((c1 (cyc1 '(0 . 1))) (c2 (cyc2 '(0 . 1) '(0 . 2))) =2D-=20 2.9.4 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZX+U3AAoJECM1h6R8IHkQt+gH/RTpcw/sGHosLVovnYXV4Vjg R8s/NSh2VSJ34h1PDGPtLnDQGRi6EwVluSLMEDrkcyzQXq08W1Cr55iN0U+9S1kH +TO/qZZc3N8XJs0LxG6PRuu29CL39quFZ/XDbzzW36Cs0AThcJKZYfWtrHLoRLmo ad77XQK60NKP7Ue/oow/oYMlVejp/mv+xIqwfi5BxiQDE9axKzq3pdgXg3tDcjDj QD1EoRXGCD48doVv3jurio1kXsqA2MeiqNSG0K4AHKd+FqSjgMzAYadGuSRmI3mw EHmBJ5EY905ShI1w4VjnrhwpKXezG7jxkHAqdqUd8c0vPYAWCtrs+pkSh9Rj+h8= =pz4E -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 02:30:48 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 06:30:48 +0000 Received: from localhost ([127.0.0.1]:57235 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjGR-00025I-Re for submit@debbugs.gnu.org; Sat, 08 Jul 2017 02:30:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44088) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjGR-000256-0g for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 02:30:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTjGI-0000zG-GA for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 02:30:41 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTjFr-0000pJ-BM; Sat, 08 Jul 2017 02:30:11 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1142 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dTjFq-0002vn-Ds; Sat, 08 Jul 2017 02:30:10 -0400 Date: Sat, 08 Jul 2017 09:30:00 +0300 Message-Id: <83wp7jl9uf.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Petton In-reply-to: <8737a858so.fsf@petton.fr> (message from Nicolas Petton on Fri, 07 Jul 2017 21:47:03 +0200) Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 27584 Cc: tino.calancha@gmail.com, monnier@IRO.UMontreal.CA, 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Nicolas Petton > Date: Fri, 07 Jul 2017 21:47:03 +0200 > Cc: 27584@debbugs.gnu.org, Tino Calancha > > + if (NILP (testfn)) > + { > + if (CONSP (car) > + && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key)))) > + return car; > + } > + else if (CONSP (car) && (!NILP (call2 (testfn, (XCAR (car)), key)))) > + { > + return car; > + } No need for braces when there's only one line to enclose. Also, no need for parentheses around "!NILP (...)". Bonus points for simplifying the code by determining TESTFN up front, then having only one of the above two clauses. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 03:02:25 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 07:02:25 +0000 Received: from localhost ([127.0.0.1]:57254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjl2-0002oR-TP for submit@debbugs.gnu.org; Sat, 08 Jul 2017 03:02:25 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34773) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjl0-0002oF-VM for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 03:02:23 -0400 Received: by mail-pf0-f180.google.com with SMTP id q85so26814394pfq.1 for <27584@debbugs.gnu.org>; Sat, 08 Jul 2017 00:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=3zfWEelsLyKE5GvwAKoneLTq2obhzulgEq8+xyoogko=; b=IjO5/vAHqq7L/Br8Z56/m8Qx/Ihp/tDsC1Rla4rwuQHW6kzOro5GlaaF8QHH20MKUi Zn51SdEbrSReUwHhOtXRMnbErUCFTKQITqHoN9E48WWh9ZAPW+BdKZpwUO2GINVkPAGp GWokrFBauFWWGtaoxN2aLOuHKWepBc+S00q2dk6GWKMR6r3RfyAfl+0ItAIKSeUzfY6T 6M0UyIr0FWbgvBlLMFnzQIJHgmTL0qnPycz8acCE/NNGgzQZW9f4nkkBpr9nCPma2M+F fcyzVKi0toRkm2QGDaOd/yVQp3guKjHBDNz8hh7fYJZxuBBzOkA8p5SRn4LQ5mC1rGJb MxqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=3zfWEelsLyKE5GvwAKoneLTq2obhzulgEq8+xyoogko=; b=kblUZVVvD6kDPowfwrvEmlBRfwpHKjogn4tlC1o6TU7zZmJNIkuCjkKWP203NZVko5 0DijoIthgRDpIVrYJn64UTT5dWyWertNVQGTQPiA8EcMWOQ98QBvTtz2GzXyvYUfaQG7 oOjc0wBtKtATnX6wRZvMU8PV1UgKJKLaRQ8OU9juhXutnbxDPY1KrIfJqoGZvLhonSFs osV4mJPdhIKvyec8vRwHB8S492XRz005CXzk6poLtoynH2HrNiL4MdSPx/hk5EokOWhl 2gzezfnGegJfQIHdlzDSynFKoh+GBasotjs23JOUxmFrAlZjUY0Zrt/TGgHSAm/r5NPZ B2rw== X-Gm-Message-State: AIVw110nNAvKPvgz2BV6r4nLW4a0USXsysgCLkB30+/g6uP6Ycjr8jTV 1gPZdba00UUJuQ== X-Received: by 10.84.241.198 with SMTP id t6mr7274843plm.48.1499497335815; Sat, 08 Jul 2017 00:02:15 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id o84sm12920832pfj.109.2017.07.08.00.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jul 2017 00:02:15 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sat, 8 Jul 2017 16:02:12 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <83wp7jl9uf.fsf@gnu.org> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Tino Calancha , monnier@iro.umontreal.ca, 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) On Sat, 8 Jul 2017, Eli Zaretskii wrote: >> From: Nicolas Petton >> Date: Fri, 07 Jul 2017 21:47:03 +0200 >> Cc: 27584@debbugs.gnu.org, Tino Calancha >> >> + if (NILP (testfn)) >> + { >> + if (CONSP (car) >> + && (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key)))) >> + return car; >> + } >> + else if (CONSP (car) && (!NILP (call2 (testfn, (XCAR (car)), key)))) >> + { >> + return car; >> + } > > No need for braces when there's only one line to enclose. > Also, no need for parentheses around "!NILP (...)". > > Bonus points for simplifying the code by determining TESTFN up front, > then having only one of the above two clauses. Do you mean something like this? { Lisp_Object tail = list; Lisp_Object fn = NILP (testfn) ? Qequal : testfn; FOR_EACH_TAIL (tail) { Lisp_Object car = XCAR (tail); if (CONSP (car) && !NILP (call2 (fn, (XCAR (car)), key))) return car; } CHECK_LIST_END (tail, list); return Qnil; } ;; This is shorter but now the default case, because the call2, is less ;; efficient than just using Fequal, right? From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 03:15:15 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 07:15:15 +0000 Received: from localhost ([127.0.0.1]:57263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjxT-000363-Cd for submit@debbugs.gnu.org; Sat, 08 Jul 2017 03:15:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49873) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTjxR-00035o-1U for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 03:15:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTjxI-0007yg-T2 for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 03:15:07 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTjxI-0007yb-PC; Sat, 08 Jul 2017 03:15:04 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1234 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dTjxH-0002mz-Q2; Sat, 08 Jul 2017 03:15:04 -0400 Date: Sat, 08 Jul 2017 10:14:54 +0300 Message-Id: <83lgnzl7rl.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: (message from Tino Calancha on Sat, 8 Jul 2017 16:02:12 +0900 (JST)) Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 27584 Cc: nicolas@petton.fr, monnier@iro.umontreal.ca, 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Tino Calancha > Date: Sat, 8 Jul 2017 16:02:12 +0900 (JST) > cc: Nicolas Petton , monnier@iro.umontreal.ca, > 27584@debbugs.gnu.org, Tino Calancha > > > Bonus points for simplifying the code by determining TESTFN up front, > > then having only one of the above two clauses. > Do you mean something like this? > > { > Lisp_Object tail = list; > Lisp_Object fn = NILP (testfn) ? Qequal : testfn; > FOR_EACH_TAIL (tail) > { > Lisp_Object car = XCAR (tail); > if (CONSP (car) && !NILP (call2 (fn, (XCAR (car)), key))) > return car; > } > > CHECK_LIST_END (tail, list); > return Qnil; > } That's one way, yes. But not necessarily the one I had in mind. > ;; This is shorter but now the default case, because the call2, is less > ;; efficient than just using Fequal, right? Is it? Did you time it? From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 07:29:33 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 11:29:33 +0000 Received: from localhost ([127.0.0.1]:57377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTnvZ-0000PO-4c for submit@debbugs.gnu.org; Sat, 08 Jul 2017 07:29:33 -0400 Received: from petton.fr ([89.234.186.68]:33140) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTnvX-0000P9-5M for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 07:29:32 -0400 From: Nicolas Petton To: Tino Calancha , Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> Date: Sat, 08 Jul 2017 13:29:20 +0200 Message-ID: <87lgnz4167.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499513364; bh=9V+XmBF62sk+Kr8FZCYVYkc4zSXb8Urv/ohL52sQ0vY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=WlhhmS8uKj32zMt8WLcTWWb+OGKVjPZkMGtb35I+Pa801PHY1rwmDs/VA5YzmyMA5VT07/v6wMtw9i3Fdmpb4CLYcODplMjDCz9nCcWcm2XXNGAYwhhegAXnMAUdUPT0r73Rg0U6XQm4Z0k+yaihSkFvQyjEb1aCvqfMC4Fj2SU= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: Tino Calancha , monnier@iro.umontreal.ca, 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Tino Calancha writes: > Do you mean something like this? > > { > Lisp_Object tail =3D list; > Lisp_Object fn =3D NILP (testfn) ? Qequal : testfn; > FOR_EACH_TAIL (tail) > { > Lisp_Object car =3D XCAR (tail); > if (CONSP (car) && !NILP (call2 (fn, (XCAR (car)), key))) > return car; > } > > CHECK_LIST_END (tail, list); > return Qnil; > } > > ;; This is shorter but now the default case, because the call2, is less=20 > ;; efficient than just using Fequal, right? I like your version more, but I also thought that it would be slower for the default case. I ran benchmark-run with the first version: (setq alist (mapcar (lambda (e) `(,(intern e) . ,e)) (locate-file-completion-table load-path (get-load-suffixes) "" nil t))) =20=20=20=20=20=20 (benchmark-run (assoc 'absent alist)) (0.00023356 0 0.0) (0.00016584 0 0.0) (0.000165243 0 0.0) (0.000164741 0 0.0) (0.000240754 0 0.0) (0.000104102 0 0.0) and with your version: (0.000556587 0 0.0) (0.000238677 0 0.0) (0.000498506 0 0.0) (0.000527675 0 0.0) (0.00064989 0 0.0) (0.000520543 0 0.0) Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZYMIQAAoJECM1h6R8IHkQ0gYH/Azy2dS7wnYIS854P7h9gYSK nl6o0eN1e9fqaRQyuvtsJ6spUhq80q5Evh/ZnOb5yZrNOkac6wp4W4ccrLaHNAT6 ILFo+bTUYd6u/jmdd4+CjQFYIMrQHHWRxKBPN3Vm7PUEbCvEQKB7LO90i2ggGykE e8DITFhRteLt6toks6sYDKHcFjS5taThBcxwnO4LSTq56zFdDwIaa6fcdgNLnywG 0aVmnZJS1DcthPeCO1MMrPHPLosO1v+Pl6lAMDuoCQvbaSfa+6kaxazLEGX53z17 LWw9mRNP0jFoTZM3mD0LugzrKrK8xHs9kvbptN87mxD4HymF0yrh+iTqcCwmBvI= =QmjV -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 07:32:22 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 11:32:22 +0000 Received: from localhost ([127.0.0.1]:57381 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTnyI-0002Hw-IN for submit@debbugs.gnu.org; Sat, 08 Jul 2017 07:32:22 -0400 Received: from petton.fr ([89.234.186.68]:33676) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTnyG-0002Ez-AV for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 07:32:20 -0400 From: Nicolas Petton To: Eli Zaretskii , Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <83lgnzl7rl.fsf@gnu.org> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> Date: Sat, 08 Jul 2017 13:32:11 +0200 Message-ID: <87inj3411g.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499513534; bh=Kzeu5TdsySISbRAOESM9yVFOMhu40EioZShpEA2aPUQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=xLdc2TY98Acf52n5/3ET9kbqmj38ZhfBX2xwnxpNd4lh7c2HzcmTfWQCOSXR9olKhNkRB/tK/fUBldGX7iwcsluP5epe4KDBC6gdYYPMmOpoaYlm8nYjbaOVWrsD2MQ0dnlPN2v46iDP6SmashvJpMQLG8TNqm2bzaE5iqUxg9k= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: monnier@iro.umontreal.ca, 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Eli Zaretskii writes: > That's one way, yes. But not necessarily the one I had in mind. What solution did you have in mind? --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZYMK7AAoJECM1h6R8IHkQBwsH/37KI/mV7GaExOZoINw/VknW Q9Lc2n0/zoYZlp3PJnUY43R45jBmpDhccL8Qvv5KrJi4vQFB6i1q0JaCh2yBuekG 07eXiP3dBMLDcw7wx0kmAMDhIsAOOCzdUwVvr42qMkjyfGaIB2WdOLVogIrg5fQP JjzCOZT3E8GmUIuPHXylZSgj4dB3/XM5TREaFTrYUywrlytjplWcd2VOcr95qZg4 wnd9LQ3Jg4jgwvI1VVEkD7Ioof0aRQn3J85fpvf88pPz0klt+Gw9iZQYNF+RM/C1 YO4GZyKqWObt6LDQwUzgTDKmm/pA0z9TvEPawKURyjDWjCXARsa1Zop/lXRwuQc= =59qn -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 08 07:46:36 2017 Received: (at 27584) by debbugs.gnu.org; 8 Jul 2017 11:46:36 +0000 Received: from localhost ([127.0.0.1]:57386 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dToC3-0002ak-R4 for submit@debbugs.gnu.org; Sat, 08 Jul 2017 07:46:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dToC1-0002aY-OU for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 07:46:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dToBs-0008Fl-M7 for 27584@debbugs.gnu.org; Sat, 08 Jul 2017 07:46:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:38654) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dToBs-0008Fh-Ib; Sat, 08 Jul 2017 07:46:24 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1863 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dToBr-0007Df-Nl; Sat, 08 Jul 2017 07:46:24 -0400 Date: Sat, 08 Jul 2017 14:46:09 +0300 Message-Id: <83a84fkv7i.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Petton In-reply-to: <87inj3411g.fsf@petton.fr> (message from Nicolas Petton on Sat, 08 Jul 2017 13:32:11 +0200) Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Nicolas Petton > Cc: monnier@iro.umontreal.ca, 27584@debbugs.gnu.org > Date: Sat, 08 Jul 2017 13:32:11 +0200 > > > That's one way, yes. But not necessarily the one I had in mind. > > What solution did you have in mind? Something like this: FOR_EACH_TAIL (tail) { Lisp_Object car = XCAR (tail); if (CONSP (car) && (NILP (testfn) ? (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))) : !NILP (call2 (testfn, XCAR (car), key)))) return car; } From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 09 10:46:04 2017 Received: (at 27584) by debbugs.gnu.org; 9 Jul 2017 14:46:04 +0000 Received: from localhost ([127.0.0.1]:58995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDTI-0000Pc-4S for submit@debbugs.gnu.org; Sun, 09 Jul 2017 10:46:04 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35807) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDTG-0000Ou-SC for 27584@debbugs.gnu.org; Sun, 09 Jul 2017 10:46:03 -0400 Received: by mail-pf0-f193.google.com with SMTP id q85so11119514pfq.2 for <27584@debbugs.gnu.org>; Sun, 09 Jul 2017 07:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=+Z77JB5Ld6rr8ra/XE6/0kR+eDrnf8j2VLfE6eEDr7A=; b=gdSxMErV6xtrQe5tNSBxMMmHzGsZ5flyhxnVOSejbD/2e4U1cSTiJcqftJPIKSh8IL md44zKPD1531Mr1HzEwGpLfa6GL+ZP0Ye3xOVBbcz/7rUKmBt6Ww6KaVpx9QX7nW2a7j R+tfLAR5V7UlvghBoCgZYJKI6yxgMDViBzjE0o1xFCAZqCamdXot5vmLA0TbczFMWUz7 D1e67RZ5Mt619Q31VMxbXPC7WSdjZf13ICdKNe1DUbHUZA3jztNTvNLVjMArpyBAN+QL SJN50YLqw/9yX7eJsIdPrx49NAMYBGh3xzY2B3TPMExDEN2AAWAY4sEGJeEXGK4+PMtL 4Elg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=+Z77JB5Ld6rr8ra/XE6/0kR+eDrnf8j2VLfE6eEDr7A=; b=fgcDGI62uwThkdu7zBIi+ywv7MoAC6YCsK44ToNhKm2pKlCQ02Z9aquar8pUbQz/jQ BRFysf0a2jduBwjcoyyhtxUeViIq4ZPgm2vwraLP1bcvtoRPPfgvGEfGd/AnWx4aj/b8 v66GbBNMLR9JuwXyXirb7jpuOoFQIYvlEd2ANFSloDh4n5vDzZd7WcLJhbZzL1kTdFjQ fDvzhp0mdz545UVEeWcszRRX5zkft7hiyOG2bwdPZq18iji8dkYU8Uu4NtcDdKfoYnj4 NZwED90bprdk2DoXkslsTnFH8roo9AJSaTUQrGzoySliDfku4S9cy6BwQmKGNo5r7RDw l/xA== X-Gm-Message-State: AIVw111GsNrV4tlTtLca3luZ9hfutfqLnRQRjqHRYk6sfhQuiEHlqNlj raFchEPI1cF8jg== X-Received: by 10.99.95.147 with SMTP id t141mr10277182pgb.263.1499611556580; Sun, 09 Jul 2017 07:45:56 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id s87sm19279321pfa.86.2017.07.09.07.45.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 07:45:55 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 9 Jul 2017 23:45:53 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Stefan Monnier Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Fri, 7 Jul 2017, Stefan Monnier wrote: >> + (declare (compiler-macro >> + (lambda (_) >> + `(pcase ,pred >> + ('eq (assq ,key ,alist)) >> + ((or 'equal 'nil) (assoc ,key ,alist)) >> + ((guard (and (macroexp-const-p ,key) (eq ,pred 'eql))) >> + (if (floatp ,key) >> + (assoc ,key ,alist) (assq ,key ,alist))) >> + (_ (assoc-default ,key ,alist ,pred nil 'full)))))) > > This replaces a call to the function with a chunk of code which does > `pcase`, which is not what we want: we want the `pcase` to be executed > during compilation and if we can't choose which branch to follow, then > we just keep the call unchanged (which is why, in my define-inline > example, the pcase was outside of `inline-quote`). Thank you Stefan. After playing a bit with this i'd like to ask you something. I rewrote it as follows: (declare (compiler-macro (lambda (form) (pcase pred (''eq `(assq ,key ,alist)) ((or ''equal 'nil) `(assoc ,key ,alist)) ((and (guard (macroexp-const-p key)) ''eql) (if (floatp key) `(assoc ,key ,alist) `(assq ,key ,alist))) (t form))))) Apparently, it works as a charm: *) For example, if i compile a file with content: ;; -*- lexical-binding: t; -*- (defun run () (assoc-predicate 999 '((1 . "a") (2 . "b")) 'eql)) *) tmp.elc contains, something like: (defalias 'run #[0 "\300\301\236\207" [999 ((1 . "a") (2 . "b"))] 2]) **) But note what happens if the file contains: ;; -*- lexical-binding: t; -*- (defun run () (assoc-predicate (let ((x 999)) x) '((1 . "a") (2 . "b")) 'eql)) **) tmp.elc shows: (defalias 'run #[0 "\300\301\211\262\302\303#\207" [assoc-predicate 999 ((1 . "a") (2 . "b")) eql] 4]) That is, in the pcase fails the condition: (and (guard (macroexp-const-p key)) ''eql) so that the compiler macro doesn't change the form. But we know that: (macroexp-const-p (let ((x 999)) x)) => t So, i would expect to **) compiles to similar code as *). What is wrong with my assumptions? From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 09 10:48:43 2017 Received: (at 27584) by debbugs.gnu.org; 9 Jul 2017 14:48:43 +0000 Received: from localhost ([127.0.0.1]:58999 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDVr-0000TE-JA for submit@debbugs.gnu.org; Sun, 09 Jul 2017 10:48:43 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:34428) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDVp-0000T2-D2 for 27584@debbugs.gnu.org; Sun, 09 Jul 2017 10:48:41 -0400 Received: by mail-pf0-f179.google.com with SMTP id q85so37792275pfq.1 for <27584@debbugs.gnu.org>; Sun, 09 Jul 2017 07:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=NGnpavKsy4Ktwif696pvS+PpyghVMLra4XBpRb+kF38=; b=bboj1QzMag2RLsttUV8GBigcKO4Vm3UdQ51kTgb5om7THZqTtCl/LvMnNhMDKUSGK9 BDGpswXMnxHI8s+1VhzdvQWKKmatC04YME3LQ6+mYokkS0qFsatDPvKDei4/EbYItDYJ 2inEgb9Jeh9TqjjCxCEtVhftlHtFNfVLH/F9z1xOMkxJiQZd9MDp9b2UZAxQvQPxghJ0 nfXi0D4pCJrMr6iwuMDWUJeCjsapaoFV+AjhjyQL8J6OGgn6PVFjaQ5YMZ9MOyOZykMe QoBZmB8xpA9einiWVXCQrUgx09umiyGdYMcsam2P/SrEGC6OqqhOlMUpTfUvDZyneiCC FdwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=NGnpavKsy4Ktwif696pvS+PpyghVMLra4XBpRb+kF38=; b=hQKsRXYiM+eGqxFZTCwtrI3pgHTe6s3DnToe24V/LYugrLRE4GUqox8wM6wuSuMCra dGMSy0wighr9QGQ9XpshkEXKHF8SsElv41sMgJOU4lAco+nf3Hl3GQY7Za8Sn6G6GFIZ uBNb9/AGOAmfD6gRLo7EtgbjetyHXgQtit+LFjPYVQFDl2hR8VgQO5TxqoU7PBJ+XPUB 3dmH50+/bIigIIj5sHwGTEiX1ltyCmfovDco0rflMc5A1Zs5imRCmF/+L7R1fvi4qcgS pDDVewiasUoa/1FNZwRY4z+VlUuSWo6qsnxz2x8f0zwsDPrDPW3ZQ8njH02ibmO3l41C a5Rw== X-Gm-Message-State: AIVw110MUcovaSGhRqh6WrC0hToV+wuPCuKFBLTX1h7ufzgLPM02Nx1n 03bIvsL6toLodw== X-Received: by 10.84.224.74 with SMTP id a10mr13759131plt.210.1499611715857; Sun, 09 Jul 2017 07:48:35 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id o73sm18678388pfi.2.2017.07.09.07.48.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 07:48:35 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 9 Jul 2017 23:48:32 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <83a84fkv7i.fsf@gnu.org> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) On Sat, 8 Jul 2017, Eli Zaretskii wrote: >> From: Nicolas Petton >> Cc: monnier@iro.umontreal.ca, 27584@debbugs.gnu.org >> Date: Sat, 08 Jul 2017 13:32:11 +0200 >> >>> That's one way, yes. But not necessarily the one I had in mind. >> >> What solution did you have in mind? > > Something like this: > > FOR_EACH_TAIL (tail) > { > Lisp_Object car = XCAR (tail); > if (CONSP (car) > && (NILP (testfn) > ? (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))) > : !NILP (call2 (testfn, XCAR (car), key)))) > return car; > } Nice! From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 09 15:18:15 2017 Received: (at 27584) by debbugs.gnu.org; 9 Jul 2017 19:18:15 +0000 Received: from localhost ([127.0.0.1]:59161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUHih-0001pf-28 for submit@debbugs.gnu.org; Sun, 09 Jul 2017 15:18:15 -0400 Received: from petton.fr ([89.234.186.68]:56546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUHie-0001pR-TB for 27584@debbugs.gnu.org; Sun, 09 Jul 2017 15:18:13 -0400 From: Nicolas Petton To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <83a84fkv7i.fsf@gnu.org> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> Date: Sun, 09 Jul 2017 21:18:01 +0200 Message-ID: <87eftp4dxy.fsf@strawberry> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499627885; bh=aGgrQemnR4zeA60Hh1y5OsvmusGqtMUvnnqKn+hIhRE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=VsZMgeFehuOy3akw+k2yMGlWrg2Zq+P6bCAbjL7BFKHO6kbcT2dUHJFk9iVMRZtZyaagy7XQa4IMosdwArOuZBaU4gDkTyY3Lq5GcQjILZF/b8emFua0wmbfwHH0lAMgr2RvXuDaN8hFoHLSMY5ZKjBjVd9cz4hHbN3PVenJ6Eo= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> What solution did you have in mind? > > Something like this: > > FOR_EACH_TAIL (tail) > { > Lisp_Object car = XCAR (tail); > if (CONSP (car) > && (NILP (testfn) > ? (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))) > : !NILP (call2 (testfn, XCAR (car), key)))) > return car; > } Thanks, it's indeed much better. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZYoFpAAoJECM1h6R8IHkQFdsIANDny+OuzC6h+pqVkkJdU8wz XYSa+elihkd4UmnrbX+RBMJAsZQeARfiydD1MqyJlmVzqDPTypViK53W5HDzNO50 +tDiAtVbsKjMDD0mKNEm1BgqIFAd23/CNPWyzokY3W85HF6Khg2bEJcpJE4M2VXj Kq0ZPBfnLLcTECv7He1s3UoxuO/6N+Bu0MWGFuP0UH0s+sEj/u8dFI0QoyXhkM0j eZrnJln2byMDhrc8/VR6tW0wOd+lJBKL1lAuD2EUVc6gpVw/2NoBvmyKVes27yG/ kPwnlztXv7VbchYMcEaHRQExltwLuygntDEz4rP38QeoFg+D7rZcORmKofXSFaw= =N39j -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 08:04:24 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 12:04:24 +0000 Received: from localhost ([127.0.0.1]:59699 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXQN-0005zH-VA for submit@debbugs.gnu.org; Mon, 10 Jul 2017 08:04:24 -0400 Received: from mout.web.de ([212.227.15.14]:61771) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXQM-0005z4-Ep for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 08:04:22 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Ls9JH-1dfprj23vb-013u5h; Mon, 10 Jul 2017 14:04:08 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> Date: Mon, 10 Jul 2017 14:04:06 +0200 In-Reply-To: (Tino Calancha's message of "Sun, 9 Jul 2017 23:45:53 +0900 (JST)") Message-ID: <87van033d5.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:mXLO6JJ4iat5N72qYn7pft0ovsTWGrog7t6rKDEcjkKqm78mGpS 8yPKhK7v51YPpuI4hQThbYlvMU93hd7Gn2z07kY/Jd9QpgLDXfwrTQz2eV4PIU5ixIlualf zilFNntmXICOorSGEHGf7N1M3C5B/enWaNYS7Rsb3Yecsj3sTNpoY9Nyl2UJ/Q/3+gAWiw9 8yCx0PYbi1alkTGplQ0gQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:1j9FL4Xd/wk=:qV+yXf22SlzxaKZrF6PJ0s wAeqw2WQN5uVoGBK5Mgscpi+LJTJ9q0k3XwrIkwZN07po7LcVveY+mDlRmD2wkTNaiyPIBNv6 klT0g3ZOc777Lm1VSyt9zKY5w7KDtZ4l73ud/faznqgfOldd/8Wju4lYSLcA57dpHgbn+JDI5 3ZAouYiEd/wNy79RdzaKGzsmSxDv3qMfD4D1zSlxZ8zqH/Obx0a2TXeMTF7GIB3fIBKsQG2Zo NKo/B0PQ/sb6ro6Vq6VPQXoxIYvbtgqXRxYPAEUtKuk+6U3tv6IgCv7hz5J7NJfJyTTURmxu2 SCVXU49Et8Y5r/hhYHWHplBqwGea1pFRHHUlUUZuorKKUvbNd4L4ZXr6EDZGC8zlnhncVDFNc 9QlrIdUjBWj2rI4r0yshYDLGr9bK6QKQFE9rgc9JNy0lDwMb2R/GQX8lCMzrL+O/ix35wkrTx 10lJiJHRXY88SoVEUBiVRZdwlO21z434B9JMbXwqMlBRJQoq3RpyuUF6T44DGEnU7V/NZMzA1 ndfGuU3SaGmYoXERq7IY+zjNRNfhMqeXoqmzVd0En3aCqEZyos4Xq7bbl3aHgY9/+Xptsi3RL 88x6YiSFc0veujG/Mh/xXP4srL//FJct7RpZUQkUdAr3/lhD1RVJoMBBBnRWCw8hveQNvduYJ xTGserp+bVDyTuzDGT4dYWRlMmH5KHoRsqaburvfMGqKMHfSdwsU/JlPnvzhpdMEDCV+b+yA+ d9T25DYmOyRejdXyeCkS2oqY+R8icfYOQ9bU03NQteLgSE+sBjSvceyGAq7U29jyG+d7BNawT a6WjrXB X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Stefan Monnier , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Tino Calancha writes: > But we know that: > (macroexp-const-p (let ((x 999)) x)) > => t Aren't you just missing a quote before the expression? Michael. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 08:28:33 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 12:28:33 +0000 Received: from localhost ([127.0.0.1]:59714 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXnl-0006Xz-1L for submit@debbugs.gnu.org; Mon, 10 Jul 2017 08:28:33 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36791) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXnk-0006Xl-4A for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 08:28:32 -0400 Received: by mail-pg0-f65.google.com with SMTP id u36so12536305pgn.3 for <27584@debbugs.gnu.org>; Mon, 10 Jul 2017 05:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=4RirRJDfhWxE2u76oIrrISWL1ziYcH74VXsH+Jp3tU4=; b=Wseo3lImprQazs+s2Mwf26865ew/cAb8EkuZAQPr+ID/eGBo9pelq/vTkJKXlNjmZA badKtNWUyM4NtMvKuXtr4VF2zM7g+iBfMFcUrmBWcYw0OBmcUwX42t80vZR177jrHsBf O0E83nMtCmZPQUff5/RRf+4y99G/DS6MuHnNQUo7XyoqmCzbC86L4zOovEUKRZqIGxXk cWrXxnEwCQiKhm/8y2kUjNWkXMKpXOFt0BvgqCWnhx0lnjilh0VfP2OpcRV8rkuqh3lP almiQG1daZ+a1I0cvgomu52nK1HEe1FPwjQRel9DZtYSAHR/KAt9micU1c435Lw26bzc XW5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=4RirRJDfhWxE2u76oIrrISWL1ziYcH74VXsH+Jp3tU4=; b=AGV10gjEmwCAvOUpnDt0RT056R2gcMMt0Yt8Dw6xJdQKa/9LO/YtXwRV57cp+FR3T1 xtxqt6rNuKkAAvVf5lV8Wm4Jrze1C644UAZGX0SDFGSAJuyjKTQYCip1l7DBq+VtRhBx zRcmv0xryLq0BvXxdbWx1ogLGVJaIwncu6FXYh1ScvOyPq5+CnX0JB7ABp4JN4POpnW/ wx/P+LKlX1P9WYdUcdHduDfvOb9oNJG7lSe/yz4rc30z5i6PD6HWoOGI6kk0bzIhb7Lw uLDYQYbyABea679UXAQiMRDHGex9P1EstaYYQX/Ac3Kp1RL5DQRyrZr7ck91KAAxnMnD 4fFA== X-Gm-Message-State: AIVw110E55xNmBdwS+7mUzkbtb0dw2ImPaP5+JekhWo7DgnXMHRqk82r nzb603ZlET1q8w== X-Received: by 10.98.64.129 with SMTP id f1mr22254327pfd.225.1499689706053; Mon, 10 Jul 2017 05:28:26 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id k194sm19939075pgc.31.2017.07.10.05.28.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 05:28:25 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Mon, 10 Jul 2017 21:28:21 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Michael Heerdegen Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87van033d5.fsf@drachen> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> <87van033d5.fsf@drachen> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, Stefan Monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On Mon, 10 Jul 2017, Michael Heerdegen wrote: > Tino Calancha writes: > >> But we know that: >> (macroexp-const-p (let ((x 999)) x)) >> => t > > Aren't you just missing a quote before the expression? That's right, the compiler macro see '(let ((x 999)) that explains my example: (macroexp-const-p '(let ((x 999)) x)) => nil I am a bit fooled by the docstring of `macroexp-const-p'. "Return non-nil if EXP will always evaluate to the same value." Consider the expression: (setq exp '(let ((x 999)) x)) This will always be evaluated to 999: (eval exp) => 999 Then, I would expect `macroexp-const-p' return non-nil on this expressio, but it doesn't. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 08:38:34 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 12:38:34 +0000 Received: from localhost ([127.0.0.1]:59722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXxS-0006u8-0K for submit@debbugs.gnu.org; Mon, 10 Jul 2017 08:38:34 -0400 Received: from mout.web.de ([217.72.192.78]:63482) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUXxP-0006tu-SM for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 08:38:32 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LwqJw-1djyKU2kUC-016S2U; Mon, 10 Jul 2017 14:38:14 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> <87van033d5.fsf@drachen> Date: Mon, 10 Jul 2017 14:38:11 +0200 In-Reply-To: (Tino Calancha's message of "Mon, 10 Jul 2017 21:28:21 +0900 (JST)") Message-ID: <87r2xo31sc.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:Y9xxeC8EeIrk8fioBm8tcceej3T1wmSUR4ikVj/v5EgwSylJSJk kOO+tzyv0QZkx/y50t0uZ/TuguGvl6191aFvyEdnrmgIfpR3HfXwCHp8ZjNRuUEw+eFSXXM BAJbajvdVjAkskKoU+UyhOpXB+OvEkD5FfsVumQpVpBKrehWMKg2lFck0nm9G69EyEUDTlu 9XTjTq6D+JKtJlG2NDzDQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:tzPe7KUSLAU=:/OKBloG9AeBN/msgaqKVfq x+SZIrCqtmWA9ulRn/dkdU3Y2VCufRT/vE9tbbH8hY80H4WMUS16MYdCXrvlWNs+98y4C/J/y S0hjECp2XzLRV1bZ4Ar5G4oQ80csyhOtyyXX3RB8gRmPC/rqhnBRSRQOwW+uOrAQKKdVJHXWN KQqdZUPWbOzRfdNOgROOhoR6FeOIEPHD4uOQ+zdYHTX+Ja2oks78YlsVFlTSQgZQOGXwtftLb pFB4TosgGZP6SFgpDbVsDIdV0m/Nn2Oy+p83JC8pZHmNQ+UuVqtb4XH1Vnl4XBzcnJRAmqCuP ghmy02bBhqRcWVriEnBHKsqCpz/BN+vzLAJfNC+5n00pLEv7BuiOedS8Lcg1MM9MJYOqtiTmz B0S5MzuaHIY54nEpSZLoa9SNTtffV6KxIKjhze2dEI1p2BlB6Gn5+pUPeMyvRx9bobH0efbcN KCZ8qcQOatAs6I9mkGrM4r448vFyKIjufEVF9855nXgm00FSnfr2ga3ENIsBMzpDFO/d7R8j0 PYcfXXXtgpZsTCUpsVSo1GKmcOgdNaxqNl1Qjz9sufUoWrQ4AtERFub+h7BJMUgh/sGe9kcQR 23N0n3pv7zmy/WSj0UMD7CYB+sET7cf4lyI3ma9MqyM1IJa2x9ibO/UU4qjDYv11sRgl+9YP/ hK7FblPDj1OCvlzRv6nZgiQpPtPATZ2hjfC/VH1k5aiqq7J6TVmBZ3R0WV7d9yG2ilDnXDOSd wauhO30pI+Wpw9WTP9WwPamn440107E2nE1YOgR3m7mAgaleGxuaZ0XMUa40VHS+9TvdJiXG8 naDT59c X-Spam-Score: -3.5 (---) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Stefan Monnier , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.5 (---) Tino Calancha writes: > I am a bit fooled by the docstring of `macroexp-const-p'. > "Return non-nil if EXP will always evaluate to the same value." Well, wouldn't a "correct" implementation solve the halting problem? But yes, the doc is misleading. Michael. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 08:48:03 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 12:48:03 +0000 Received: from localhost ([127.0.0.1]:59730 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUY6c-000785-TT for submit@debbugs.gnu.org; Mon, 10 Jul 2017 08:48:03 -0400 Received: from mout.web.de ([212.227.15.14]:52530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUY6b-00077b-0V for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 08:48:01 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MQ8vL-1dY6T94Avz-005Iav; Mon, 10 Jul 2017 14:47:49 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> Date: Mon, 10 Jul 2017 14:47:47 +0200 In-Reply-To: (Tino Calancha's message of "Sun, 9 Jul 2017 23:45:53 +0900 (JST)") Message-ID: <87mv8c31cc.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:Yw6CbPHkZgai9vn0ITJK3Rxm89s62tUcmmi7QkkfHmRcdy2CxeQ 6JNjQTxV2/6pJs6s6YQhY2vFLP6geQyhCkicIWmmNX6byvT3XLbt+DJRaNF8rXVZY6dc/b/ uVkADDAivL39J9slU/JPCVi/j7Dsuxd4czCrCGu28QQv+iIarVnd1E/AJ56hDKMGvyAjGnW aEYHLsG14LfhzHEtBREng== X-UI-Out-Filterresults: notjunk:1;V01:K0:qzXyIlwp35Q=:n5ZXJ1dk9zspUHtjwm1Nhu WlUvV2JdKlvwpUJWayQ/7yPkZlVGnb8LQ+lcRt+8FFEjFBNrQhUFfae781olaDsjE2hHnVIhO FltfoCkWO/5tAJZ981gKZuDsgynNMayaRQLVhC98XvMItZO/fDkhsyBpXuscERS3CMEgi9P0C XbNRdgtqOltQ+HYM+ztMIAL8eT11TK5Sd8JqtqsbC35Al53kB9pGlT66KEVzXqDXQQmEbvIl4 31V8WLwSo0k36+bpc2/EGnsqw6lV2hK9Hn4uB91cPJDyICAgHZ6TbwiRvMVCuVKtQndP4vPyx c77h3ROWFT/iiqKa+Qbsjh0th4/zFWqdoST5Bgc8dNfk52F8GKGGk2iZzuAkFQX18BCRKLHOL JXkh0WRdQtI636hZOZH1NrAu4M/35xmkmgVNl+gtBPgHoff8n0JIiEfNqR4t+7VRCpd3Jqu4q jz9uNLViLPgjTIKZF2Sr13Cm3tRur9feZ8ctumcYGs042uqSvZKTiPERV0+MvrvcYgCtxKrWh oXTne/7cx1IsPDb9yW63k5UUCOi2xhwDywUeBHJGtNZw+NPUI81psI54iZM4LnGnQiEHr15oy 37RqbWQhO13Qgq2kXCBoWh00luiDe2iMvtyg5stg0npMK2N7IYR4cfX8YLQ0s4dphQAHSVuLy LqcsXoCEDXNqcqcf9FVwoLOTZkK078rxJFoZp0tncOn3DCjSvrm5NCyJXc6kuny4js2W8nDfQ qMpA0p6rBhd1JLxXUar3+/0UkumKQbLFZIs1HuP9Jt+0RvDQkdSqSVLYpybN0ol6ZOtuUNnxN eqQLBen X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Stefan Monnier , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Tino Calancha writes: > I rewrote it as follows: > > (declare (compiler-macro > (lambda (form) > (pcase pred > (''eq `(assq ,key ,alist)) > ((or ''equal 'nil) `(assoc ,key ,alist)) > ((and (guard (macroexp-const-p key)) ''eql) > (if (floatp key) > `(assoc ,key ,alist) `(assq ,key ,alist))) > (t form))))) Is this a good idea in general? PRED could also be function-quoted, or a variable bound to `eq'. And KEY could be an expression that evaluates to a float. That would fail the `floatp' test. Michael. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 08:50:57 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 12:50:57 +0000 Received: from localhost ([127.0.0.1]:59734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUY9R-0007C8-Av for submit@debbugs.gnu.org; Mon, 10 Jul 2017 08:50:57 -0400 Received: from mout.web.de ([212.227.15.14]:49741) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUY9P-0007Bu-5l for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 08:50:55 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MX0q4-1d9XFc0fBc-00VuMp; Mon, 10 Jul 2017 14:50:40 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> Date: Mon, 10 Jul 2017 14:50:38 +0200 In-Reply-To: <8737a83fq6.fsf@calancha-pc> (Tino Calancha's message of "Fri, 07 Jul 2017 15:48:01 +0900") Message-ID: <87inj0317l.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:ZIdF/xxDlC9cC9/wgUu2y32WKLN/WBg8d5bVj6CoUgfSf284okB FumBBcrkF0MDkNOjXqVYjMpsoz4TjuemnQcnuKMWC2bn4A+qZ9AVagnA5esPZKOMYn8L+EC /hK4p64rccaATQKp9XsDpLfkqfxZ4rdMxuqQqd7upJz1uhBkiazHEf+lQeoBOwBpZbXLmrF 5p8Yszesyzyvew9vUuJOA== X-UI-Out-Filterresults: notjunk:1;V01:K0:LUGJAQzkDVk=:UDREVDaRmhJ7IWAG4UesNM 6eeyUWvjkoioTUzOL6k3+l3oBWrCNFmynJYD31uExDRmW9WFfHQt8oAbKS74guAXk3TZ5aD7A dXAJz9vCikGdScakd1HCI2j/Ze36NEUF+q1nzM0C1zce9SXG2t+UoPlQFHRoCAwT5Ii6r5ev9 UIyzzh0qLgEn/K2J8AcstQBqd8et1vnPOCuuB0DNxgNuAusulbc+kDqTD77xLf+L3aioCOvWU vecf+CeiF2hvgPnp/bbqd+UThXYDmGvS8mUasvFKEuSrtrOtmcdmzNYe4sscmULfMoxA4kuYc Ow2jrHNPkK480O3MfsoXDSAInu4Klhq25ixSlL972Yvl+KR/dKXl1ZxujGjbnEWIWNwzUsIhk dMqN24LTIXB6/gwa/L9KAtyfKGHr1mYHHK3Q7+q/dIRYI9XrvdjYjJDrnsi5qYBTe6jd4fZfH I56B9rDoVskWTgvydnVLT4pZAmaEmw/smE79py2v/Ar3bJcdIsf6Z4SdcXRNZIeDRJg7cq4kQ ZQ0U48ex8f1CEsupPCTU96oIRXR2CRe30V0kpvU6+3kc8i3xWxOOpkmY+Di4N1azEBBQm3y60 1CV2L+6RvrtcP5nCFhxh0hcp3cNDgjUGZIqiJp/jVMDVCIW4D0xWrnDxg3V81oBmtBkfxQpRp p650y4YxYVdf/1552Db/WyRe7HoTy4rE8aNaPfPYspHo3UvwmhZ8f5H0qba9AV0ohb6pITi7+ If4iGttyEsT9zHtFK2Nu2ROE6fdvJHr6K9TbW0ZPQIR0V6lAPUBga4kgOvhLH1aLCmqk9Tmf0 yR/5y4j X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Tino Calancha writes: > +(defun assoc-predicate (key alist &optional pred) > + "Like `assoc' but compare keys with TEST." ^^^^ Nitpick: That should be "PRED". Michael. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 09:02:48 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 13:02:48 +0000 Received: from localhost ([127.0.0.1]:59752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUYKu-0007Ur-9x for submit@debbugs.gnu.org; Mon, 10 Jul 2017 09:02:48 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUYKt-0007Uf-88 for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 09:02:47 -0400 Received: by mail-pf0-f194.google.com with SMTP id e199so14446721pfh.0 for <27584@debbugs.gnu.org>; Mon, 10 Jul 2017 06:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=WV0wSaZYtOjiwyKCgxlQ//bTWJl9uk7QjaFUzAkbKCA=; b=TWphoKb4qojxU/f8wrgUW5M6Kyv5gEz0N3i0o5/nLUnR+T09A4Y4X7O6Qd7SLvIifl OyKAd6k4px82slTV8U0gRGtswZ93Z70gvPDLUiiZOBirA6roPDDPHgtq6fM91O8ayFcM KmE3n1vasd30hkAGIH2UMFcH34L4tVcW0dzRRIejsIAfvcm9V9tvqGz/6JcbLkHTf0fT t/Yvnss1rN5HMeRy3POlQfTa+m3lG1BSEHDheEhwaz8Q6IvshqesYdylyuJdJzrgCpTB 8ef5AkmOKvDOlXnwcb+FaW7Rd9OnUYKcQ20fANCuxiFZQFX/dDrBLAXCQ2N3UMfnM2ks 6bbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=WV0wSaZYtOjiwyKCgxlQ//bTWJl9uk7QjaFUzAkbKCA=; b=lsYnLL6FE21s972ZJl8kq3aHlL0KgZhPk8yEvFWDA9NUQ8gKfxoqICbbKUc4bNINs4 otFDI9e7GPfhGEKGIFfOZx03C9T2BTmCHRpJ6ZBTSmOWM/Rk0ziXqxn9ZdZcDyL4S2P1 wv104eRJM332iMn322HjussvNFz6vzakJ8kuSut906VdEZ1ZYTJAq6TpsuOj8mvVon93 PjfuqYmQeP1kcYY/QSOtktVoRxpNvTucVIaIJbbf7jPZWTy1PGgdumIiqGrZE++BnFfF iKSHGQhT4f5bj79ZYYwuzpBknZM1H/7eCzxeNTzWzABUGqs0iWiVN6p55ovHkQup8vc/ l3YA== X-Gm-Message-State: AIVw110bZrAS5O6OcspfoHZ2Lm/F0LJGHhcf7qNsGWmP0JSKFG8QxxkI Y8MHp2Y8TBE8HA== X-Received: by 10.98.71.212 with SMTP id p81mr45463024pfi.106.1499691761287; Mon, 10 Jul 2017 06:02:41 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id m196sm29457581pga.33.2017.07.10.06.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 06:02:40 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Mon, 10 Jul 2017 22:02:34 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Michael Heerdegen Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87mv8c31cc.fsf@drachen> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> <87mv8c31cc.fsf@drachen> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, Stefan Monnier , Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Mon, 10 Jul 2017, Michael Heerdegen wrote: > Tino Calancha writes: > >> I rewrote it as follows: >> >> (declare (compiler-macro >> (lambda (form) >> (pcase pred >> (''eq `(assq ,key ,alist)) >> ((or ''equal 'nil) `(assoc ,key ,alist)) >> ((and (guard (macroexp-const-p key)) ''eql) >> (if (floatp key) >> `(assoc ,key ,alist) `(assq ,key ,alist))) >> (t form))))) > > Is this a good idea in general? PRED could also be function-quoted, or > a variable bound to `eq'. And KEY could be an expression that evaluates > to a float. That would fail the `floatp' test. Well, this code is now in the 'Limbo', because we are thinking to use the Nico solution (`assoc' having an optional arg PRED). That said, its fun to discuss about it. You know, this compiler macro is inspired in the one used by `cl-assoc' i.e., `cl--compiler-macro-assoc'. If you find a problem on it, then the same problem might arise in `cl-assoc' :-S From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 09:18:43 2017 Received: (at 27584) by debbugs.gnu.org; 10 Jul 2017 13:18:43 +0000 Received: from localhost ([127.0.0.1]:59769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUYaJ-0007s4-El for submit@debbugs.gnu.org; Mon, 10 Jul 2017 09:18:43 -0400 Received: from mout.web.de ([212.227.17.12]:60485) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUYaH-0007rq-Ow for 27584@debbugs.gnu.org; Mon, 10 Jul 2017 09:18:42 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MgfJz-1dHXdq3Csh-00O079; Mon, 10 Jul 2017 15:18:29 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> <87mv8c31cc.fsf@drachen> Date: Mon, 10 Jul 2017 15:18:26 +0200 In-Reply-To: (Tino Calancha's message of "Mon, 10 Jul 2017 22:02:34 +0900 (JST)") Message-ID: <8737a4mnvh.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:m219PV0vEYlL1KlIX59297AIlOUmT4JiUuNGBg0Rs9M9Sr02KqI ANcc5cUvHnPAiII8U6Pb9NrXkptkCph5+BADB0aOWWuOvqB2HzhknchwvG1GqxctM9QslKr ZRFRobt5GDROG0vvvnUCbKIy5fWLeMZjXpBKwut1stm+cdXjvPpGvd+cF/q1yHFC0BxBBe4 i5U7yhQBTGfJ8pE5KH95Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:lVNNNLkEo6s=:L2RRIWpX/Zdket0DY2xEQo IlnPL1BQLqYbwCOlmy6lnwo3IhFp+QX8WLfARIT649bY6Kcm9MtnC84mISZFxRVMpoXZDQhPm c1rWePyf95UANO2Jk8fom0MAv91Ya3Dvl9s3UM0ALaOsmCNCyhXQziO+SQirZxeYmLrhsjYU+ pODvOWlKb4uOOF553wBGQIEE8cFyA/+JhIy29x1YUA80TP3/EV7a6tnsJMY3NFIoc+ZAb3n6/ IThfGrRcpWKcEG3W4gBvH0L1YO9IQ7RA1M8xkmPYOzi2rbUQItv3Mqa14M00R53Gt0AZl8vTB kO0rFVSyXPAYM6XIwR3ptL3EquLw7ZEkSamB97R/u9l3EQpu9TDDVzRKU0kJAomsLZ2BcKxOg hu4iL1LVNhBgujwSU0tHfUPFliYS9+HkbftKoXdi1q3/0HLFFPryfCyoR8h1TP5dOBxP+ToRQ QiS/sgXqSXn8DombV8r0fYFhjbAYGVUUebapA7vDjFxIYfYFXQSP+Y+lfWqQ1l7mAiEJqPMRn /zFS9V6YtYbSz1CCzvGsDeMRSy5FolwOUHgOoE09VnSDch6xAHQA8B9jewch8+6YDa6smR3U2 kON2pDPCIvGl9LMiyen1WFDHdQNo4C31eUF6bIMvIlAZA+L6ZePkt5/fhqWTNKI3nj/WCVCPK XUsOEE7WrEkLCbZxZwsorO/vm7TvVB0qevTHbDTtvKCBsP2WbIHJyn+rlDXhn33IZwiXo5Qwc xhdeeywI4CDFm4KjIHbyjYrWtmosph5UabTIzvdLnMq38lGFkACvE1HVVauWjtns84ZSJZYcT ewp5cOs X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , Stefan Monnier , 27584@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Tino Calancha writes: > > Is this a good idea in general? PRED could also be function-quoted, > > or a variable bound to `eq'. And KEY could be an expression that > > evaluates to a float. That would fail the `floatp' test. > Well, this code is now in the 'Limbo', because we are thinking > to use the Nico solution (`assoc' having an optional arg PRED). > That said, its fun to discuss about it. > You know, this compiler macro is inspired in the one used by > `cl-assoc' i.e., `cl--compiler-macro-assoc'. If you find a problem > on it, then the same problem might arise in `cl-assoc' :-S I was wrong about your handling of KEY, I think it is ok. For the PRED, `cl--compiler-macro-assoc' uses `cl--const-expr-val' that DTRT for function quoting. The compile time optimization is limited but doesn't look wrong. Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 11 04:08:49 2017 Received: (at 27584) by debbugs.gnu.org; 11 Jul 2017 08:08:49 +0000 Received: from localhost ([127.0.0.1]:33329 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUqDx-0000AZ-GH for submit@debbugs.gnu.org; Tue, 11 Jul 2017 04:08:49 -0400 Received: from petton.fr ([89.234.186.68]:34448) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUqDv-0000AM-MX for 27584@debbugs.gnu.org; Tue, 11 Jul 2017 04:08:48 -0400 From: Nicolas Petton To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <83a84fkv7i.fsf@gnu.org> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> Date: Tue, 11 Jul 2017 10:08:40 +0200 Message-ID: <8737a3qttj.fsf@strawberry> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1499760521; bh=j4kVD07ChYXbZkEQocneB/nxGrZ26tB8PTrpDfVyLtE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=EYEHSRIxyUcoAKJ2CpW2QGayMkFJlUl2w55UZan5y97c8zRwclNR4qcEX/6YSqnSccTMwSmWwT/kmUQuXSdEViejHX7Zh4xEuyJ1mb84hBh4Xyh1uxOd7L9oUDGov9EBXCTao8g3Ro66DUtV1AFBtkSM75gQqfo2A4ct5Q9vn+M= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Eli Zaretskii writes: > Something like this: > > FOR_EACH_TAIL (tail) > { > Lisp_Object car = XCAR (tail); > if (CONSP (car) > && (NILP (testfn) > ? (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))) > : !NILP (call2 (testfn, XCAR (car), key)))) > return car; > } I installed your version in master. Tino, would you like to adapt your patch to use the new assoc? Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZZIeIAAoJECM1h6R8IHkQqzsIAJzLqizGAC48DJ8vQ15YF0cl zEUemBL+PFmAzYni1IPpxjy2lIDBwu4ZJpddMtyZ1zzan4i1hhewV9jgk20mCJWv 9J9W/2ADLgTlZ9H9ZgGDviBpYbcHb4+CY3VtgngDoQQrdQtoVDPmska2jaGi6ocA PaFak3mKjpYFbHKlTKTHLNmkIRZISrowl0I82X+Z2tqW47P/v61KU7gbspnG+/Mt uWa/8Bb0griSTnp8Bc/tHEyb9MlxM/6T7YrV70rgt6kDgUFLkzSTsbtAK4XCNCz9 U20gTkcqYI+39MACuNF2exiU0wlUbpWYCrnchsfVLVf2cZsIENgkm5P2zMhDe3o= =rNFy -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 11 05:20:10 2017 Received: (at 27584) by debbugs.gnu.org; 11 Jul 2017 09:20:10 +0000 Received: from localhost ([127.0.0.1]:33369 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUrL0-0001om-10 for submit@debbugs.gnu.org; Tue, 11 Jul 2017 05:20:10 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:36602) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUrKy-0001oZ-Lt for 27584@debbugs.gnu.org; Tue, 11 Jul 2017 05:20:09 -0400 Received: by mail-pg0-f52.google.com with SMTP id u62so63606705pgb.3 for <27584@debbugs.gnu.org>; Tue, 11 Jul 2017 02:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=DL5WzO76JDOQEH0RMHjj8gPlQWXOTsDSsy+pRZnqEHg=; b=Ei1sRmo11eBEREhyFYqxBShAe0FpCt95q3d4MHwEYjUjsnxgPfGnCGxsTiMnpiXsCN 7YZJpcVZIrj/KkooeI4t9KuAHxqtmK/f4zLS9isauVdH2i5tYsXyHZvWq6wj4tWLB7CG QXtBZ6NbHVJ9fJOWhb0cDA9Fu58eMUnutP3XLXScJL7vUPwuur/Wo5cTPn8CL3fsWAv3 QcEychsipo9YvbV5YjRScOolPl6Pkm0Ob48NGpj3IEj27l/k873qPoVY63Gak96i/PMH GE7ym+qFByItSvtKBrzxGFl4NXh8qnsfGxuqRs31IMrxlLPeMkOmS80tiknGdg8gA0w/ Hnng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=DL5WzO76JDOQEH0RMHjj8gPlQWXOTsDSsy+pRZnqEHg=; b=XG66tcocz2gkcr2SsmSCRvb6i2sUicFSc3toZRbhBkGDfmbuLEHnaM10memS+0O0sb zqg4eacyYHEHVSY+E1FaCnZRKgn489Ne7jql8Up9LwfVdpM36vNgYnw04SgzopZpIo5U gLz5d3vbxzZpO2QW/RYvBDShkkIw4up9KgKuY8U2mENBfeSE8gzB8JLTwc6aF7DSdL6W plWfHUvdGdp/q6ZcSdXnwMsL6uky6/GL2XPjwsOqUqQw35hP7qhRURtNXm4CkG054Yb/ O5h7W03j6DmbGVSsmgwEHVob+S0Y0lS+4mZsFCsy9UhLwUzQtsah919XGGoAVNsrHp0z LBTQ== X-Gm-Message-State: AIVw111Chrx51l/wRla0WC99klzfoxNb/YPJWkUS6Vb4L4Av1oeF7t86 BBdKjPwpzLEQ6g== X-Received: by 10.99.163.26 with SMTP id s26mr19319026pge.232.1499764802645; Tue, 11 Jul 2017 02:20:02 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id w66sm29859111pfi.63.2017.07.11.02.20.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2017 02:20:02 -0700 (PDT) From: Tino Calancha To: Nicolas Petton Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> Date: Tue, 11 Jul 2017 18:19:56 +0900 In-Reply-To: <8737a3qttj.fsf@strawberry> (Nicolas Petton's message of "Tue, 11 Jul 2017 10:08:40 +0200") Message-ID: <871spnwcsj.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 27584 Cc: Eli Zaretskii , 27584@debbugs.gnu.org, monnier@iro.umontreal.ca X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Nicolas Petton writes: > Tino, would you like to adapt your patch to use the new assoc? Here we are: --8<-----------------------------cut here---------------start------------->8--- commit 2a9fb44ddae0acbd09c3123f06981d291163e765 Author: Tino Calancha Date: Tue Jul 11 18:17:00 2017 +0900 alist-get: Add optional arg TESTFN If TESTFN is non-nil, then it is the predicate to lookup the alist. Otherwise, use 'eq' (Bug#27584). * lisp/subr.el (alist-get): Add optional arg FULL. * lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN. * lisp/emacs-lisp/gv.el (alist-get): Update expander. * doc/lispref/lists.texi (Association Lists): Update manual. * etc/NEWS: Announce the changes. * test/lisp/emacs-lisp/map-tests.el (test-map-put-testfn-alist) (test-map-elt-testfn): New tests. diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 966d8f18b1..39353b6de6 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1589,16 +1589,20 @@ Association Lists @end smallexample @end defun -@defun alist-get key alist &optional default remove -This function is like @code{assq}, but instead of returning the entire -association for @var{key} in @var{alist}, -@w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}. -If @var{key} is not found in @var{alist}, it returns @var{default}. - -This is a generalized variable (@pxref{Generalized Variables}) that -can be used to change a value with @code{setf}. When using it to set -a value, optional argument @var{remove} non-@code{nil} means to remove -@var{key} from @var{alist} if the new value is @code{eql} to @var{default}. +@defun alist-get key alist &optional default remove testfn +This function is similar to @code{assq}. It finds the first +association @w{@code{(@var{key} . @var{value})}} by comparing +@var{key} with @var{alist} elements, and, if found, returns the +@var{value} of that association. If no association is found, the +function returns @var{default}. Comparison of @var{key} against +@var{alist} elements uses the function specified by @var{testfn}, +defaulting to @code{eq}. + +The return value is a generalized variable (@pxref{Generalized +Variables}) that can be used to change a value with @code{setf}. When +using it to set a value, optional argument @var{remove} non-@code{nil} +means to remove @var{key}'s association from @var{alist} if the new +value is @code{eql} to @var{default}. @end defun @defun rassq value alist diff --git a/etc/NEWS b/etc/NEWS index 68ebdb3c15..eb61e7d182 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1105,6 +1105,9 @@ break. * Lisp Changes in Emacs 26.1 ++++ +** New optional argument TESTFN in 'alist-get', 'map-elt' and 'map-put'. + ** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index c5c12a6414..27376fc7f9 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -377,10 +377,12 @@ setf `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) (gv-define-expander alist-get - (lambda (do key alist &optional default remove) + (lambda (do key alist &optional default remove testfn) (macroexp-let2 macroexp-copyable-p k key (gv-letplace (getter setter) alist - (macroexp-let2 nil p `(assq ,k ,getter) + (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq))) + (assoc ,k ,getter ,testfn) + (assq ,k ,getter)) (funcall do (if (null default) `(cdr ,p) `(if ,p (cdr ,p) ,default)) (lambda (v) diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index a89457e877..31ba075c40 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; Keywords: convenience, map, hash-table, alist, array -;; Version: 1.1 +;; Version: 1.2 ;; Package: map ;; Maintainer: emacs-devel@gnu.org @@ -93,11 +93,13 @@ map-let ((arrayp ,map-var) ,(plist-get args :array)) (t (error "Unsupported map: %s" ,map-var))))) -(defun map-elt (map key &optional default) +(defun map-elt (map key &optional default testfn) "Lookup KEY in MAP and return its associated value. If KEY is not found, return DEFAULT which defaults to nil. -If MAP is a list, `eql' is used to lookup KEY. +If MAP is a list, `eql' is used to lookup KEY. Optional argument +TESTFN, if non-nil, means use its function definition instead of +`eql'. MAP can be a list, hash-table or array." (declare @@ -106,30 +108,33 @@ map-elt (gv-letplace (mgetter msetter) `(gv-delay-error ,map) (macroexp-let2* nil ;; Eval them once and for all in the right order. - ((key key) (default default)) + ((key key) (default default) (testfn testfn)) `(if (listp ,mgetter) ;; Special case the alist case, since it can't be handled by the ;; map--put function. ,(gv-get `(alist-get ,key (gv-synthetic-place ,mgetter ,msetter) - ,default) + ,default nil ,testfn) do) ,(funcall do `(map-elt ,mgetter ,key ,default) (lambda (v) `(map--put ,mgetter ,key ,v))))))))) (map--dispatch map - :list (alist-get key map default) + :list (alist-get key map default nil testfn) :hash-table (gethash key map default) :array (if (and (>= key 0) (< key (seq-length map))) (seq-elt map key) default))) -(defmacro map-put (map key value) +(defmacro map-put (map key value &optional testfn) "Associate KEY with VALUE in MAP and return VALUE. If KEY is already present in MAP, replace the associated value with VALUE. +When MAP is a list, test equality with TESTFN if non-nil, otherwise use `eql'. +TESTFN, if non-nil, means use its function definition instead of +`eql'. MAP can be a list, hash-table or array." - `(setf (map-elt ,map ,key) ,value)) + `(setf (map-elt ,map ,key nil ,testfn) ,value)) (defun map-delete (map key) "Delete KEY from MAP and return MAP. diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166..d9d918ed12 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -725,15 +725,18 @@ rassq-delete-all (setq tail tail-cdr)))) alist) -(defun alist-get (key alist &optional default remove) - "Return the value associated with KEY in ALIST, using `assq'. +(defun alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. This is a generalized variable suitable for use with `setf'. When using it to set a value, optional argument REMOVE non-nil means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. - (let ((x (assq key alist))) + (let ((x (if (not testfn) + (assq key alist) + (assoc key alist testfn)))) (if x (cdr x) default))) (defun remove (elt seq) diff --git a/test/lisp/emacs-lisp/map-tests.el b/test/lisp/emacs-lisp/map-tests.el index 07e85cc539..15b0655040 100644 --- a/test/lisp/emacs-lisp/map-tests.el +++ b/test/lisp/emacs-lisp/map-tests.el @@ -63,6 +63,11 @@ with-maps-do (with-maps-do map (should (= 5 (map-elt map 7 5))))) +(ert-deftest test-map-elt-testfn () + (let ((map (list (cons "a" 1) (cons "b" 2)))) + (should-not (map-elt map "a")) + (should (map-elt map "a" nil 'equal)))) + (ert-deftest test-map-elt-with-nil-value () (should (null (map-elt '((a . 1) (b)) @@ -94,6 +99,13 @@ with-maps-do (should (eq (map-elt alist 2) 'b)))) +(ert-deftest test-map-put-testfn-alist () + (let ((alist (list (cons "a" 1) (cons "b" 2)))) + (map-put alist "a" 3 'equal) + (should-not (cddr alist)) + (map-put alist "a" 9) + (should (cddr alist)))) + (ert-deftest test-map-put-return-value () (let ((ht (make-hash-table))) (should (eq (map-put ht 'a 'hello) 'hello)))) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-11 Repository revision: 0bece6c6815cc59e181817a2765a4ea752f34f56 From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 12 13:36:39 2017 Received: (at 27584) by debbugs.gnu.org; 12 Jul 2017 17:36:39 +0000 Received: from localhost ([127.0.0.1]:35722 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVLYz-0001iy-F2 for submit@debbugs.gnu.org; Wed, 12 Jul 2017 13:36:39 -0400 Received: from mout.web.de ([212.227.15.4]:64817) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVLYx-0001il-VP for 27584@debbugs.gnu.org; Wed, 12 Jul 2017 13:36:36 -0400 Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MfCyA-1dJhWf1w66-00OlRA; Wed, 12 Jul 2017 19:36:23 +0200 From: Michael Heerdegen To: Tino Calancha Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <871spnwcsj.fsf@calancha-pc> Date: Wed, 12 Jul 2017 19:36:19 +0200 In-Reply-To: <871spnwcsj.fsf@calancha-pc> (Tino Calancha's message of "Tue, 11 Jul 2017 18:19:56 +0900") Message-ID: <87h8yhy2uk.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:gC6EK8ruy2V5jG3vmF4YCOV5s/DQr3bVy1lmqWBGRepStXtMbTP MzUXeAsNK5vueQnJ8CZyTTubOIfPIL8z9BygPzycz4xO5PQbffAr5ZfV6+jdDZeqQ9uWDDg Y5e+Hp2LDV4Od84xMOK/p1oyezLUPLmMB+uiJ36oU0kmkBJVq31rDpnjqCNfgtrlc6qqP+2 YBWrb+yGWP4H4nfzKrtaw== X-UI-Out-Filterresults: notjunk:1;V01:K0:SrgPHhCGH7E=:N/m2ysTdJRhE7y4TXXLj4s 4k50lGULxBf2Dzn5iGBKKxSplJ5dBRDQVyxvX3CV7BhidKeOv1p+Rm55MJ/0iQPN61+1w5u8u 4Ybt1YmScP7CbQuqEG/FKMjnM1mPfXtx2KswYiwwB/VgvFv3Lsk0ei1QnCieE1hssDP60fzUb S7PAa0Ki0g6WgmfhK1k98rRdJGUeWcyxBzj6vckXIxYzLPvIfAfTY/8iKvzo4JigCfPvhdBg9 ajUC9jCZ5dh4Nhu9h8Yk5Z1qe40qbZXPeDXcS0va1F9+leZRi7p4SDiE4dfGj9yTAX4+mqums v5NYfTY6MrJIi6IVSa2O19UyhT6t03rYVEglXzq62jaat2Q+XiIQudvHcIKYUoRBz2bYPvnud YYc8HQk4+hUi55xX3ldu6qRxUY9bY5heXdH5kUxYKuXK9k7D+3/Z3acWREQejdzuUMeKFTdVI 5DNrymtdNEhfgzFT+bgVMsNgaMsASHC6Yt0R7YlnqfDfilmuZa7LitaMqbVu+hLaeGc5WW5WB oWDwzfToTxyxJsUXKpLKx2d5aQKq9OFtjhYCYDSLkyWIP6XjStApiqOZP5QjJ/joxKHaNlplh 7RDMUwQVTGSIjG1scKFIuINcxiQ5Lyadz0wSZ4Ys0GutVPpXeDoANEW+fKztl6UbnGvOY9N/K zM2Hdr1fSiW/410OCbjT6+LKpNXKU8vFsip4hWy10WWOoYr8IGTpgtCZPeRFmvhHWaFcIJM3k HZnE4MPFCpXv57/vdePuoXh8uuiVBhPN8rPFyDMDGLXQmW+Cg/4yMvsifVE6CYdhGAmOtmmx7 +shwZUh X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, monnier@iro.umontreal.ca X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Tino Calancha writes: > -@defun alist-get key alist &optional default remove > [...] > -This is a generalized variable (@pxref{Generalized Variables}) that > +The return value is a generalized variable (@pxref{Generalized I don't think this is good wording. When `alist-get' returns 1, do we really want to call `1' a generalized variable? What is settable is the place (expression), so I think we instead call the expression of the function call "generalized variable". Michael. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 14 01:19:17 2017 Received: (at 27584) by debbugs.gnu.org; 14 Jul 2017 05:19:17 +0000 Received: from localhost ([127.0.0.1]:37609 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVt0W-00083i-UW for submit@debbugs.gnu.org; Fri, 14 Jul 2017 01:19:17 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:35724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVt0U-00083U-UI for 27584@debbugs.gnu.org; Fri, 14 Jul 2017 01:19:15 -0400 Received: by mail-pf0-f176.google.com with SMTP id c73so40007639pfk.2 for <27584@debbugs.gnu.org>; Thu, 13 Jul 2017 22:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=/mOWIw2gasereWkBV14pgCIVVUgodwCHA0Zu9codNa0=; b=BV5SspZpt+W34xQQxOBc8f9WfMSJAHSsOAusWm0tkRbmhFqJLZZUDBNBu/T2nCtqwH xCORKz94SAP/UQDvmhuYEtZ8VZ2gXBjViQAABg72DlAHkrbMAackRu63hAS9OWeTfMw7 OYuVMucXplhCnWTiynMObpmymmLOAOEq5ne5OzdPAOw89R8kCd0gQyTBaDgeb/BbCmiI O/He+QV7D7mpIlKhgqbl/96tINyTh4Ba32bVW7pWpmaR9rCcXzBc8lCcQ/AM3zzNr+Uk AO5Ylvg9ZEEa7k3gCC8RNap6LJscsGIrlq8lPg955Mbrv6jI1l96Y9nmY+DpVbwdBixt FFLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=/mOWIw2gasereWkBV14pgCIVVUgodwCHA0Zu9codNa0=; b=ikKcjdVYgSbW05qH+BowB7aAlKJqER0dqRlqD6rALAULhpo22XlYTpeVSirGrPv7Y8 POTs9DMLRn8V0DSaLp0CNYP88kNWF85X7Ren+xPwDaRZ14xQThf9ztwcSZMmXHcbdMad tD1rEEZxBeFjyIPlgGLaTbAZ6EQVTXMUJC+5Sz0q0C0o0e8uxnCqWHWmSI2p6I/VsgFk qcBCZQoxb755g8NvjMmAUM0ahzmvaScVPzKnzXO5N4zDa6tQvIqx2XnW1FR7d1IJCsBs birOgn3KfLeykjsYJv/93CnCgfegEjmJGXxx9gaixBHZEnpQNP3lGkEikwXk9AwvX3OR z+zw== X-Gm-Message-State: AIVw113WerhDgTkb8Gw8HSZRjRXs8NZTWh2ZoAta6IWtIpK6S5X9DQSb ID0rxIa72yPjyA== X-Received: by 10.84.193.36 with SMTP id e33mr14154903pld.122.1500009548812; Thu, 13 Jul 2017 22:19:08 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id t4sm14600991pgs.22.2017.07.13.22.19.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 22:19:08 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Fri, 14 Jul 2017 14:19:04 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Michael Heerdegen Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87h8yhy2uk.fsf@drachen> Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <871spnwcsj.fsf@calancha-pc> <87h8yhy2uk.fsf@drachen> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27584 Cc: Nicolas Petton , 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On Wed, 12 Jul 2017, Michael Heerdegen wrote: > Tino Calancha writes: > >> -@defun alist-get key alist &optional default remove >> [...] >> -This is a generalized variable (@pxref{Generalized Variables}) that >> +The return value is a generalized variable (@pxref{Generalized > > I don't think this is good wording. When `alist-get' returns 1, do we > really want to call `1' a generalized variable? > > What is settable is the place (expression), so I think we instead call > the expression of the function call "generalized variable". thank you, agreed. I will keep the original: 'This is a generalized variable ...' instead of: 'The return value is a ...' I will push it in a few days if there are no issues to address. Tino From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 14 07:16:55 2017 Received: (at 27584) by debbugs.gnu.org; 14 Jul 2017 11:16:56 +0000 Received: from localhost ([127.0.0.1]:37789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVyad-0003ic-ON for submit@debbugs.gnu.org; Fri, 14 Jul 2017 07:16:55 -0400 Received: from petton.fr ([89.234.186.68]:37228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVyab-0003iN-EU for 27584@debbugs.gnu.org; Fri, 14 Jul 2017 07:16:53 -0400 From: Nicolas Petton To: Tino Calancha , Michael Heerdegen Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <871spnwcsj.fsf@calancha-pc> <87h8yhy2uk.fsf@drachen> Date: Fri, 14 Jul 2017 13:16:41 +0200 Message-ID: <87fudzuv3a.fsf@strawberry> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1500031007; bh=p6DBr9c+HdJur+FdmXxYy7QWuBi79IQ0riqjYqUJSkU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=rC7sKK7uYX6CxOBH0qbiae88nbX6r/SZtoJhrig/bzy0mnCLFp7Wof8PkE7GubGJDRsflCD2ns2cf5fYqlJJU5J5fUP+Ddoq0XbNYlsOgbS0GwCreeeRzBtlsgWTnrMI2FU3nbv4Lpl0XQZLh2rNiCRSv/VG9bgvBfKcRFsjw34= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Tino Calancha writes: > I will push it in a few days if there are no issues to address. Great, thanks! Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEKNO+2FH986tX/vk8IzWHpHwgeRAFAlloqBkACgkQIzWHpHwg eRBt3gf8D32u7EcMOcCITjkJIYtB8/8fnc2tZEHhNh+O2wdnD2WOjN65QF6t79sh jfSEX1iy7sNLYULkJQ1mtYW9x3QJ+qjqCkQQRrWZUJisCsmZWU/FRJqk595Z4i4L mtwWigK7rYoLvmVzwc2JP7JrPA1vXUgVOP2Tc6Sj3jgWypJe1/lmWMlV3fZUVvSD /tQFxGyMHZhgfkBP/sdGw3Y4GUwFWISBgkn+CKaS0e51ZGrIkZkfnJ8khb2Een/a 84BAC9KnNV/83rqC91DQvQ3ymErNXNoC8p7LubBQ/i9q0fIPYzkVJ7Z/2keTDb+n NeEvPMtqUFAmhPheaPhdtzIae/Gs2A== =Obqu -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 17 09:38:30 2017 Received: (at 27584-done) by debbugs.gnu.org; 17 Jul 2017 13:38:30 +0000 Received: from localhost ([127.0.0.1]:43420 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dX6EH-0006ED-Ox for submit@debbugs.gnu.org; Mon, 17 Jul 2017 09:38:29 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35139) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dX6EF-0006E0-UC for 27584-done@debbugs.gnu.org; Mon, 17 Jul 2017 09:38:28 -0400 Received: by mail-pf0-f180.google.com with SMTP id e199so15575870pfh.2 for <27584-done@debbugs.gnu.org>; Mon, 17 Jul 2017 06:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=mBUELCTBwLmXpGv+KWUuTGAJzmtEBrKzJ/b4RYtfxUk=; b=Sod1wX80mTQ8UZ+ZxBRqQxFYGzfpmC0LNokvBBXD/hVA+urOEfTrbpFlJTzSUMx/AN 4JgX1voIlPYUbO3N+whnGj7jSkpSjGHxVoupM00UMj4p1lWSZNQLW5nadsC7z4hXWEVJ zAtv9nshC+bucRuSw4cpqYnGc2Q0o6hD+C8i9Uyr0KyntTOUjf+VkabDyt8KjxrbEff1 fNdP0q+KHqdZFQIoN3C002Rq8X4dWvzJtWkNbcCpMCRQra40zb+hoAQBzpJNNOsEc0Pu VKJ4lVtsXCfrL09coDJselp0UBK6pew1jc2bv82yAHRbBCtGnB1xfoCcM3VIrnHQ29zl 3atw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=mBUELCTBwLmXpGv+KWUuTGAJzmtEBrKzJ/b4RYtfxUk=; b=EoxUFZnFnyFJHUM+83ej/5F1hp+BXpLFzfoMAHAokUVeMpE0vwwXXePNaRd/kptv8v 4yfQ3MQUOwhW09Y8aYmD9j9s0b+tIQOkP6JaW61Yt02fX+bAEVgXQWX064xZEIuVxF1Y u/WPSV7p8LFmKguCCIkRO/8ieU4MfZhbPvcJxWP66FT1zD/RRl1sJV1urol19HF5rhms eF8NuJiu8H0BMPo7SBuqFaz1SOvqjyzXz70RCgoeckEVxtjzuX5l02tGtbYZ8HvA7fzm dV5HwyNNl3RAGBPWHpRvLxJs8pea6Cm85mk8UBIm3DOrm2O9XK0a2fW38KptQwHOp9U4 nPVg== X-Gm-Message-State: AIVw1131fFcPS30dzfPCa6hW3VeFovjmKvSBNdcN9cZuqqyBs7TiPNNl /SiafFGbD7Lvo99X X-Received: by 10.99.184.2 with SMTP id p2mr28988773pge.194.1500298701905; Mon, 17 Jul 2017 06:38:21 -0700 (PDT) Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id i5sm27375759pgk.61.2017.07.17.06.38.20 for <27584-done@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Jul 2017 06:38:21 -0700 (PDT) From: Tino Calancha To: 27584-done@debbugs.gnu.org Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <871spnwcsj.fsf@calancha-pc> <87h8yhy2uk.fsf@drachen> <87fudzuv3a.fsf@strawberry> Date: Mon, 17 Jul 2017 22:38:17 +0900 In-Reply-To: <87fudzuv3a.fsf@strawberry> (Nicolas Petton's message of "Fri, 14 Jul 2017 13:16:41 +0200") Message-ID: <871spffak6.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 27584-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) Nicolas Petton writes: > Tino Calancha writes: > >> I will push it in a few days if there are no issues to address. Implemented in master branch as commit 76e1f7d00fbff7bf8183ba85db2f67a11aa2d5ce From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 01 12:38:01 2017 Received: (at 27584) by debbugs.gnu.org; 1 Aug 2017 16:38:01 +0000 Received: from localhost ([127.0.0.1]:37161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcaBE-0005I6-Jw for submit@debbugs.gnu.org; Tue, 01 Aug 2017 12:38:00 -0400 Received: from petton.fr ([89.234.186.68]:59758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcaBC-0005Hr-DR for 27584@debbugs.gnu.org; Tue, 01 Aug 2017 12:37:59 -0400 From: Nicolas Petton To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <8737a3qttj.fsf@strawberry> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> Date: Tue, 01 Aug 2017 18:37:38 +0200 Message-ID: <87h8xrckh9.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1501605471; bh=Ge5AlDbktWYdZY6ki9UiR3P+AcE0q+jdzK4szNZ5Dg4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=hjIzLXd9GfwyAfKJYr3+19QAmqUeZ2Hg1sYBdMVbcswLTyqaT+XNfVFvKQKaYzug4894zu7kR59t0vyirzRjLLlRJMn02IZ4yZQMC34cfsnBovpiMfosJvAdtTGRv9k0Jc4b28nVzpRDUFDbeqZETFpC99QwEaDQNxnGx1LURKA= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Nicolas Petton writes: > Eli Zaretskii writes: > >> Something like this: >> >> FOR_EACH_TAIL (tail) >> { >> Lisp_Object car =3D XCAR (tail); >> if (CONSP (car) >> && (NILP (testfn) >> ? (EQ (XCAR (car), key) || !NILP (Fequal (XCAR (car), key))) >> : !NILP (call2 (testfn, XCAR (car), key)))) >> return car; >> } > > I installed your version in master. Here's another patch that adds a similar `testfn' parameter to `rassoc': From=20103f7a5cdd80961e654fca879aba1b9a67d4eb22 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Tue, 1 Aug 2017 18:29:34 +0200 Subject: [PATCH] Add an optional testfn parameter to rassoc * src/fns.c (rassoc): Add an optional testfn parameter. When non-nil, use this parameter for comparison instead of equal. * src/fontset.c (fs_query_fontset): Update usage of Frassoc. * test/src/fns-tests.el (test-rassoc-tesfn): Add unit tests for the new testfn parameter. * etc/NEWS: * doc/lispref/lists.texi: Document the change. =2D-- doc/lispref/lists.texi | 6 ++++-- etc/NEWS | 3 ++- src/fns.c | 15 ++++++++++----- src/fontset.c | 2 +- test/src/fns-tests.el | 6 ++++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 0c99380682..321246de12 100644 =2D-- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1550,8 +1550,10 @@ Association Lists =20 @defun rassoc value alist This function returns the first association with value @var{value} in =2D@var{alist}. It returns @code{nil} if no association in @var{alist} has =2Da @sc{cdr} @code{equal} to @var{value}. +@var{alist}, comparing @var{key} against the alist elements using +@var{testfn} if non-nil, or @code{equal} if nil (@pxref{Equality +Predicates}). It returns @code{nil} if no association in @var{alist} +has a @sc{cdr} @code{equal} to @var{value}. =20 @code{rassoc} is like @code{assoc} except that it compares the @sc{cdr} of each @var{alist} association instead of the @sc{car}. You can think of diff --git a/etc/NEWS b/etc/NEWS index 44f5ff5bde..50734b846f 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -105,7 +105,8 @@ The effect is similar to that of "toolBar" resource on = the tool bar. * Changes in Emacs 26.1 =20 +++ =2D** The function 'assoc' now takes an optional third argument 'testfn'. +** The functions 'assoc' and 'rassoc ' now take an optional third +argument 'testfn'. This argument, when non-nil, is used for comparison instead of 'equal'. =20 diff --git a/src/fns.c b/src/fns.c index d849618f2b..9e7d47253f 100644 =2D-- a/src/fns.c +++ b/src/fns.c @@ -1474,17 +1474,22 @@ The value is actually the first element of LIST who= se cdr is KEY. */) return Qnil; } =20 =2DDEFUN ("rassoc", Frassoc, Srassoc, 2, 2, 0, =2D doc: /* Return non-nil if KEY is `equal' to the cdr of an element= of LIST. =2DThe value is actually the first element of LIST whose cdr equals KEY. *= /) =2D (Lisp_Object key, Lisp_Object list) +DEFUN ("rassoc", Frassoc, Srassoc, 2, 3, 0, + doc: /* Return non-nil if KEY is equal to the cdr of an element of = LIST. +The value is actually the first element of LIST whose cdr equals KEY. + +Equality is defined by TESTFN is non-nil or by `equal' if nil. */) + (Lisp_Object key, Lisp_Object list, Lisp_Object testfn) { Lisp_Object tail =3D list; FOR_EACH_TAIL (tail) { Lisp_Object car =3D XCAR (tail); if (CONSP (car) =2D && (EQ (XCDR (car), key) || !NILP (Fequal (XCDR (car), key)))) + && (NILP (testfn) + ? (EQ (XCDR (car), key) || !NILP (Fequal + (XCDR (car), key))) + : !NILP (call2 (testfn, XCDR (car), key)))) return car; } CHECK_LIST_END (tail, list); diff --git a/src/fontset.c b/src/fontset.c index 74018060b8..4666b607ba 100644 =2D-- a/src/fontset.c +++ b/src/fontset.c @@ -1184,7 +1184,7 @@ fs_query_fontset (Lisp_Object name, int name_pattern) name =3D Fdowncase (name); if (name_pattern !=3D 1) { =2D tem =3D Frassoc (name, Vfontset_alias_alist); + tem =3D Frassoc (name, Vfontset_alias_alist, Qnil); if (NILP (tem)) tem =3D Fassoc (name, Vfontset_alias_alist, Qnil); if (CONSP (tem) && STRINGP (XCAR (tem))) diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index e294859226..83d7935a41 100644 =2D-- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -379,6 +379,12 @@ dot2 (should (eq (assoc "b" alist #'string-equal) (cadr alist))) (should-not (assoc "b" alist #'eq)))) =20 +(ert-deftest test-rassoc-testfn () + (let ((alist '((a . "1") (b . "2")))) + (should-not (rassoc "1" alist #'ignore)) + (should (eq (rassoc "2" alist #'string-equal) (cadr alist))) + (should-not (rassoc "2" alist #'eq)))) + (ert-deftest test-cycle-rassq () (let ((c1 (cyc1 '(0 . 1))) (c2 (cyc2 '(0 . 1) '(0 . 2))) =2D-=20 2.13.3 Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEKNO+2FH986tX/vk8IzWHpHwgeRAFAlmArlIACgkQIzWHpHwg eRCidQf/Th9RTUvAZzMwdcZ39HGqu9Ub38V0KNRd6YB3p5tZ47kz9xj5qMUKwQd2 Cit7xdpoWilwmFIjJnEerObs96Fyg3JpsC46BeMat3MBhJRkfsCxUVugHKOdkKBo QSkK/BDTzATc0+Ygznhh9E8CULhAIKTEWHmQE6hGmZwxGUyZ6eAdCVxoYCYWUPus 3NdyVBSG7LsZZEkzwYaDbHANW22+cmq66ktFdfwysmql4tZj07V5m2E+x9+0vcEj GheIEGO4l0oxTNZZyIOyrI/yjVsr/7VQvdCqRFx2eCENFmj5x3ETSpJYpcwVmBkS wF4InKo2AmEUF08dIf7DJU7rUOrr9A== =jOAR -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 01 12:49:56 2017 Received: (at 27584) by debbugs.gnu.org; 1 Aug 2017 16:49:56 +0000 Received: from localhost ([127.0.0.1]:37167 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcaMl-0005YM-Sl for submit@debbugs.gnu.org; Tue, 01 Aug 2017 12:49:56 -0400 Received: from petton.fr ([89.234.186.68]:33606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcaMk-0005Y9-Dz for 27584@debbugs.gnu.org; Tue, 01 Aug 2017 12:49:55 -0400 From: Nicolas Petton To: Eli Zaretskii Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN In-Reply-To: <87h8xrckh9.fsf@petton.fr> References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <87h8xrckh9.fsf@petton.fr> Date: Tue, 01 Aug 2017 18:49:43 +0200 Message-ID: <87efsvcjx4.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1501606188; bh=sYTqvHThv3p3hEyLwvY09ReLRwpHkVp4jIWgatlmLOU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=LauStnGyMuWj44Qkd3Y0EGkuN/XYbQr1uUpYUZgXpM5MNPp1SElyEcZjm4MNrA0u/7hjwag7VztgeQr/xgfJ5VSInIyJjrLXJv6XoHmS81JOVw+1jGjkvsSaNZ8EPzAfmPejjB5POBHam4jpBhvBupzmuxi6UJMRO6szVl2tfDs= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Nicolas Petton writes: > Here's another patch that adds a similar `testfn' parameter to > `rassoc': See the updated patch below which fixes the documentation: From=2000bd0ef08a9cbb68adbdc5add1f45d8234887d6e Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Tue, 1 Aug 2017 18:29:34 +0200 Subject: [PATCH] Add an optional testfn parameter to rassoc * src/fns.c (rassoc): Add an optional testfn parameter. When non-nil, use this parameter for comparison instead of equal. * src/fontset.c (fs_query_fontset): Update usage of Frassoc. * test/src/fns-tests.el (test-rassoc-tesfn): Add unit tests for the new testfn parameter. * etc/NEWS: * doc/lispref/lists.texi: Document the change. =2D-- doc/lispref/lists.texi | 8 +++++--- etc/NEWS | 3 ++- src/fns.c | 15 ++++++++++----- src/fontset.c | 2 +- test/src/fns-tests.el | 6 ++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 0c99380682..49913294f7 100644 =2D-- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1548,10 +1548,12 @@ Association Lists that it ignores certain differences between strings. @xref{Text Comparison}. =20 =2D@defun rassoc value alist +@defun rassoc value alist &optional testfn This function returns the first association with value @var{value} in =2D@var{alist}. It returns @code{nil} if no association in @var{alist} has =2Da @sc{cdr} @code{equal} to @var{value}. +@var{alist}, comparing @var{value} against the alist elements using +@var{testfn} if non-nil, or @code{equal} if nil (@pxref{Equality +Predicates}). It returns @code{nil} if no association in @var{alist} +has a @sc{cdr} equal to @var{value}. =20 @code{rassoc} is like @code{assoc} except that it compares the @sc{cdr} of each @var{alist} association instead of the @sc{car}. You can think of diff --git a/etc/NEWS b/etc/NEWS index 44f5ff5bde..8662766426 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -105,7 +105,8 @@ The effect is similar to that of "toolBar" resource on = the tool bar. * Changes in Emacs 26.1 =20 +++ =2D** The function 'assoc' now takes an optional third argument 'testfn'. +** The functions 'assoc' and 'rassoc' now take an optional third +argument 'testfn'. This argument, when non-nil, is used for comparison instead of 'equal'. =20 diff --git a/src/fns.c b/src/fns.c index d849618f2b..9e7d47253f 100644 =2D-- a/src/fns.c +++ b/src/fns.c @@ -1474,17 +1474,22 @@ The value is actually the first element of LIST who= se cdr is KEY. */) return Qnil; } =20 =2DDEFUN ("rassoc", Frassoc, Srassoc, 2, 2, 0, =2D doc: /* Return non-nil if KEY is `equal' to the cdr of an element= of LIST. =2DThe value is actually the first element of LIST whose cdr equals KEY. *= /) =2D (Lisp_Object key, Lisp_Object list) +DEFUN ("rassoc", Frassoc, Srassoc, 2, 3, 0, + doc: /* Return non-nil if KEY is equal to the cdr of an element of = LIST. +The value is actually the first element of LIST whose cdr equals KEY. + +Equality is defined by TESTFN is non-nil or by `equal' if nil. */) + (Lisp_Object key, Lisp_Object list, Lisp_Object testfn) { Lisp_Object tail =3D list; FOR_EACH_TAIL (tail) { Lisp_Object car =3D XCAR (tail); if (CONSP (car) =2D && (EQ (XCDR (car), key) || !NILP (Fequal (XCDR (car), key)))) + && (NILP (testfn) + ? (EQ (XCDR (car), key) || !NILP (Fequal + (XCDR (car), key))) + : !NILP (call2 (testfn, XCDR (car), key)))) return car; } CHECK_LIST_END (tail, list); diff --git a/src/fontset.c b/src/fontset.c index 74018060b8..4666b607ba 100644 =2D-- a/src/fontset.c +++ b/src/fontset.c @@ -1184,7 +1184,7 @@ fs_query_fontset (Lisp_Object name, int name_pattern) name =3D Fdowncase (name); if (name_pattern !=3D 1) { =2D tem =3D Frassoc (name, Vfontset_alias_alist); + tem =3D Frassoc (name, Vfontset_alias_alist, Qnil); if (NILP (tem)) tem =3D Fassoc (name, Vfontset_alias_alist, Qnil); if (CONSP (tem) && STRINGP (XCAR (tem))) diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index e294859226..83d7935a41 100644 =2D-- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -379,6 +379,12 @@ dot2 (should (eq (assoc "b" alist #'string-equal) (cadr alist))) (should-not (assoc "b" alist #'eq)))) =20 +(ert-deftest test-rassoc-testfn () + (let ((alist '((a . "1") (b . "2")))) + (should-not (rassoc "1" alist #'ignore)) + (should (eq (rassoc "2" alist #'string-equal) (cadr alist))) + (should-not (rassoc "2" alist #'eq)))) + (ert-deftest test-cycle-rassq () (let ((c1 (cyc1 '(0 . 1))) (c2 (cyc2 '(0 . 1) '(0 . 2))) =2D-=20 2.13.3 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEKNO+2FH986tX/vk8IzWHpHwgeRAFAlmAsScACgkQIzWHpHwg eRAyUgf+Ibh0V6gsVJNwGQx0rqb8UwwaxdJoisDPp9TRIycQXwttYWhaT6XeRHD4 /bIwixJ9n107pTPxRlYf50jaCotfYuvEeNTq5HYbZBFEBwYyyqoshy7tULO0EmyY uHlK+36FeeqjNSENV0w5xQlLhffayK77fGJZFMWaovRjqD8BpGFz5xcqbBWCyGYs CLuyRnjV+Nji2EtApS1QxLbRI3QNvIXWS8QWi2HKG2FxoOxWGcGepCDoSvMQTA1V vOptvfDpn2d1JjqhB9A7E7J5ctE7+XDfyVQNolobQs0OVzbGq2UYQjvpPXFGiGxB YuQaZrRQwBfl1SsaEmQpwM82c4Ziug== =3YeI -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 01 14:54:08 2017 Received: (at 27584) by debbugs.gnu.org; 1 Aug 2017 18:54:08 +0000 Received: from localhost ([127.0.0.1]:37256 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dccIx-0008Ol-OV for submit@debbugs.gnu.org; Tue, 01 Aug 2017 14:54:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dccIw-0008OP-I3 for 27584@debbugs.gnu.org; Tue, 01 Aug 2017 14:54:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dccIq-0005GU-MY for 27584@debbugs.gnu.org; Tue, 01 Aug 2017 14:54:01 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dccIk-0005CU-F6; Tue, 01 Aug 2017 14:53:54 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1029 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dccIh-0003B8-Mu; Tue, 01 Aug 2017 14:53:54 -0400 Date: Tue, 01 Aug 2017 21:53:29 +0300 Message-Id: <83r2wvyv9y.fsf@gnu.org> From: Eli Zaretskii To: Nicolas Petton In-reply-to: <87efsvcjx4.fsf@petton.fr> (message from Nicolas Petton on Tue, 01 Aug 2017 18:49:43 +0200) Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8760f562bo.fsf@petton.fr> <877ezk3g4p.fsf@calancha-pc> <874luovf7a.fsf@petton.fr> <87shi8tzkr.fsf@petton.fr> <8737a858so.fsf@petton.fr> <83wp7jl9uf.fsf@gnu.org> <83lgnzl7rl.fsf@gnu.org> <87inj3411g.fsf@petton.fr> <83a84fkv7i.fsf@gnu.org> <8737a3qttj.fsf@strawberry> <87h8xrckh9.fsf@petton.fr> <87efsvcjx4.fsf@petton.fr> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 27584 Cc: 27584@debbugs.gnu.org, monnier@iro.umontreal.ca, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Nicolas Petton > Cc: tino.calancha@gmail.com, 27584@debbugs.gnu.org, monnier@iro.umontreal.ca > Date: Tue, 01 Aug 2017 18:49:43 +0200 > A few comments: > * doc/lispref/lists.texi: Document the change. This should state the node in parentheses (as if it were a function). > +@defun rassoc value alist &optional testfn > This function returns the first association with value @var{value} in > -@var{alist}. It returns @code{nil} if no association in @var{alist} has > -a @sc{cdr} @code{equal} to @var{value}. > +@var{alist}, comparing @var{value} against the alist elements using > +@var{testfn} if non-nil, or @code{equal} if nil (@pxref{Equality The "if nil" part is confusing, because you actually mean "if @var{testfn} is nil". Also, "nil" should be in @code. > +Predicates}). It returns @code{nil} if no association in @var{alist} > +has a @sc{cdr} equal to @var{value}. That reference to cdr is a surprise. the original description talked about cdr right from the start, but the new one doesn't. Thanks. From unknown Sat Aug 16 00:29:51 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 30 Aug 2017 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator