GNU bug report logs - #76413
[PATCH] New macro 'compf' for composing functions

Previous Next

Package: emacs;

Reported by: Eshel Yaron <me <at> eshelyaron.com>

Date: Wed, 19 Feb 2025 13:53:02 UTC

Severity: wishlist

Tags: patch

Full log


View this message in rfc822 format

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eshel Yaron <me <at> eshelyaron.com>, 76413 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#76413: [PATCH] New macro 'compf' for composing functions
Date: Wed, 19 Feb 2025 10:40:01 -0800
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 114 days ago.

Previous Next


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