Subject: bug#76413: [PATCH] New macro 'compf' for composing functions

From: Eshel Yaron <[email-masked]>
Date: Sun, 23 Feb 2025 07:48:50 +0100

Hi,

Stefan Kangas <[email-masked]> writes:

> Eshel Yaron <[email-masked]> 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