From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Nicolas Petton Newsgroups: gmane.emacs.bugs Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Date: Tue, 01 Aug 2017 18:49:43 +0200 Message-ID: <87efsvcjx4.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1501606222 20882 195.159.176.226 (1 Aug 2017 16:50:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 Aug 2017 16:50:22 +0000 (UTC) Cc: tino.calancha@gmail.com, 27584@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 01 18:50:18 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcaN4-0004pV-6P for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Aug 2017 18:50:14 +0200 Original-Received: from localhost ([::1]:43726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcaN8-0006NH-9Y for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Aug 2017 12:50:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcaMw-0006KG-BB for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2017 12:50:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcaMs-0007OM-9c for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2017 12:50:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34490) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dcaMs-0007OA-5k for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2017 12:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dcaMr-0005Yj-Lj for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2017 12:50:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Petton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Aug 2017 16:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27584 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27584-submit@debbugs.gnu.org id=B27584.150160619621354 (code B ref 27584); Tue, 01 Aug 2017 16:50:01 +0000 Original-Received: (at 27584) by debbugs.gnu.org; 1 Aug 2017 16:49:56 +0000 Original-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 Original-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 In-Reply-To: <87h8xrckh9.fsf@petton.fr> 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135225 Archived-At: --=-=-= 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----- --=-=-=--