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: Stefan Monnier
Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Thu, 06 Jul 2017 11:07:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>>> 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





reply via email to

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