GNU bug report logs -
#76413
[PATCH] New macro 'compf' for composing functions
Previous Next
Full log
Message #26 received at 76413 <at> debbugs.gnu.org (full text, mbox):
Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs <at> gnu.org> writes:
> 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)
> - ...
Why not name it `compose` as in CL and ELisp?
How about a function with a compiler macro?
This bug report was last modified 168 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.