GNU bug report logs -
#76413
[PATCH] New macro 'compf' for composing functions
Previous Next
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tags: patch
This patch adds a new macro 'compf' that streamlines the common pattern
of function composition.
Namely, instead of (lambda (x) (foo (bar (baz x)))), with this macro we
can write (compf foo bar baz), which expands to exactly the same form.
This is similar in essence to the "compose" function proposed in
https://lists.gnu.org/archive/html/emacs-devel/2021-02/msg01138.html
with the main difference that compf is a macro, not a function, so it
incurs no runtime performance penalty.
There are many occurrences of function composition in the Emacs code
base alone that can be simplified with this macro. For example:
- In lisp/calc/calc-mode.el:
(lambda (v) (symbol-value (car v))) => (compf symbol-value car)
- In lisp/dired-aux.el:
(lambda (dir) (not (file-remote-p dir))) => (compf not file-remote-p)
- In lisp/env.el:
(lambda (var) (getenv (upcase var))) => (compf getenv upcase)
- In lisp/mail/smtpmail.el:
(lambda (s) (intern (downcase s))) => (compf intern downcase)
- In lisp/net/tramp-container.el:
(lambda (line) (car (split-string line))) => (compf car split-line)
- ...
Best,
Eshel
[0001-New-macro-compf-for-composing-functions.patch (text/patch, attachment)]
This bug report was last modified 113 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.