Subject: Re: bug#17623: 24.4.50; incorrect example for `apply-partially' in (elisp) `Calling Functions'

From: Stefan Kangas <[email-masked]>
Date: Sat, 23 Oct 2021 04:05:51 -0700

Michael Heerdegen <[email-masked]> writes:

> I disagree.  The paragraph in the manual explains what the arity of the
> function returned by `apply-partially' would be.
>
> Directly following is an example suggesting that (apply-partially '+ 1)
> is equivalent to #'1+ - which obviously contradicts that preceding
> paragraph.
>
> I'm a bit confused that you don't consider this a problem, and also that
> you said there were no concrete suggestions.

I have re-read the paragraph, and I have to say that IMO it is clear as
is written.  But I understand that you feel that it is not.

> There were concrete suggestions for improvements.  One was to simply
> spell out the function that is constructed.  It is only one line, and
> would make the semantics clear.

Instead of going into all that, can't we just find an example where the
arity doesn't present any problems?  Any ideas for something like that?

How about zerop?

    (defalias 'zerop (apply-partially '= 0)
      "Return t if argument is zero.")

But I guess `=' is also N-ary...

> BTW, whenever I posted an example using `apply-partially', Stefan told
> me that it would be more efficient to write out the lambda.  That aspect
> could also be covered: when is worth using?

That could be useful to add, I agree.

> Or delete that paragraph, better to say nothing than to confuse readers.

I think it should be kept.  Performance is not the only consideration.

    (apply-partially #'fun foo bar baz)

    (lambda (&rest args) (apply #'fun foo bar baz args))

It's obviously a matter of style but I find the former easier to read
than the latter.