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


View this message in rfc822 format

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: Nicolas Petton <nicolas <at> petton.fr>, 27584 <at> debbugs.gnu.org
Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Thu, 06 Jul 2017 11:07:14 -0400
>>> 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




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

Previous Next


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