[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`
From: |
Michael Heerdegen |
Subject: |
bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook` |
Date: |
Mon, 05 Jul 2021 01:15:25 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Some other languages have the ability to add names to anonymous
> functions (yes, a contradiction in terms) to aid debugging and the like.
> We could also extend our `lambda' with an optional name -- it seems like
> that could be generally useful beyond this particular use case -- and
> then this new add-hook function could refuse to accept name-less
> lambdas...
BTW, I think you can have something like that by misusing advice,
e.g. (example at the end):
#+begin_src emacs-lisp
(defalias 'function-name-advice #'identity) ;just a tag
(defun named-function (f name)
(unless (and (functionp f)
(not (symbolp f)))
(error "Not an anonymous function"))
(when (advice-function-member-p 'function-name-advice f)
(error "Already has a name"))
(add-function :filter-return (var f) 'function-name-advice `((name . ,name)))
f)
(defun function-name (f)
(and (advice-function-member-p 'function-name-advice f)
(cdr (assoc 'name (advice--props f)))))
;; Example:
(setq my-test-lambda (lambda (n) (+ 2 n)))
(setq my-named-test-lambda
(named-function my-test-lambda "Moon Child")) ;; => [bytecode lambda]
(funcall my-named-test-lambda 3) ;; => 5 (works)
(function-name my-named-test-lambda) ;; => "Moon Child"
#+end_src
Michael.
- bug#47992: [External] : bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, (continued)
- bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Richard Stallman, 2021/07/05
- bug#47992: [External] : bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Drew Adams, 2021/07/05
- bug#47992: [External] : bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Michael Heerdegen, 2021/07/05
- bug#47992: [External] : bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Richard Stallman, 2021/07/07
- bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Arthur Miller, 2021/07/06
- bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Richard Stallman, 2021/07/07
- bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Arthur Miller, 2021/07/07
bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`,
Michael Heerdegen <=
bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`, Olivier Certner, 2021/07/06