bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Tino Calancha
Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Sat, 8 Jul 2017 16:02:12 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)



On Sat, 8 Jul 2017, Eli Zaretskii wrote:

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]