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


Message #40 received at 76413 <at> debbugs.gnu.org (full text, mbox):

From: Eshel Yaron <me <at> eshelyaron.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 76413 <at> debbugs.gnu.org
Subject: Re: bug#76413: [PATCH] New macro 'compf' for composing functions
Date: Sun, 23 Feb 2025 07:48:50 +0100
Hi,

Stefan Kangas <stefankangas <at> gmail.com> writes:

> Eshel Yaron <me <at> eshelyaron.com> writes:
>
>>> Why not name it `compose` as in CL and ELisp?
>>
>> It's a slightly different construct then Common Lisp's compose, so I
>> feel like calling it by that name could lead to wrong expectations.
>> Another option is fcomp instead of compf, BTW, if that seems better.
>
> If it is different, then I agree that a different name is in probably in
> order.  But see below.
>
>>> How about a function with a compiler macro?
>>
>> That's a valid alternative, but it'd require quoting function names,
>> which is slightly less concise/convenient.
>>
>> Do you see a clear advantage for using a function in this case?
>
> It's slightly less typing, but also risks being more unclear, as it has
> different evaluation rules.  The name `compf` is similarly fine, but to
> me comes off as a little bit cryptic.

I think it strikes a good balance between being concise and being
cryptic, like "incf" does.  But naming things is hard...

> I think allowing function names to be in variables is also more general
> and thus flexible, for instance supporting things like:
>
>     (let ((fun #'some-function))
>       (mapcar (compose #'not fun) some-list))

compf supports that use case, see the docstring.  
I think it's actually more general than the "compose" function, since it
also supports macros, such as ignore-errors:

(mapcar (compf ignore-errors read-from-string) '("foo" "bar" "baz"))

But that's an accidental benefit.  The salient difference is the ability
to pass function names unquoted.

> I also forgot to say thanks for digging up the old thread and this idea.
> It had completely fallen off my radar.

No problem,

Eshel




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.