GNU bug report logs - #27584
26.0.50; alist-get: Add optional arg TESTFN

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Wed, 5 Jul 2017 03:24:02 UTC

Severity: wishlist

Found in version 26.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #77 received at 27584 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Nicolas Petton <nicolas <at> petton.fr>, Tino Calancha <tino.calancha <at> gmail.com>,
 monnier <at> iro.umontreal.ca, 27584 <at> debbugs.gnu.org
Subject: Re: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Sat, 8 Jul 2017 16:02:12 +0900 (JST)

On Sat, 8 Jul 2017, Eli Zaretskii wrote:

>> From: Nicolas Petton <nicolas <at> petton.fr>
>> Date: Fri, 07 Jul 2017 21:47:03 +0200
>> Cc: 27584 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
>>
>> +      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?




This bug report was last modified 7 years and 353 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.