GNU bug report logs -
#76413
[PATCH] New macro 'compf' for composing functions
Previous Next
Full log
Message #43 received at 76413 <at> debbugs.gnu.org (full text, mbox):
Eshel Yaron <me <at> eshelyaron.com> writes:
> 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...
Sure. It's not as clear as "compose" of course, but if we are going to
have a new name, I can't think of anything better.
>> 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'm not sure that this benefit is large enough to justify having a
macro, given the reduced clarity of not quoting as we do everywhere
else, and then feeling forced to rename it to the more awkward "compf"
instead of "compose".
One drawback of unquoted function names is that the byte-compiler won't
recognize them as functions, I think. It could, but it would require
more code, making things more complicated in the process. The same goes
for any other tooling. Right?
So I'm asking again if it isn't easier to just have the quote?
This bug report was last modified 169 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.