Subject: Re: bug#66908: Exposing more public nadvice API

From: Visuwesh <[email-masked]>
Date: Sat, 04 Nov 2023 00:20:00 +0530

[வெள்ளி நவம்பர் 03, 2023] Stefan Monnier wrote:

>> Specifically `advice-cd*r' would be useful,
>
> It's clearly the internal function most frequently used outside of
> `nadvice.el`, indeed.
> I think it'd be OK to promote that function to a non-internal name.

It would be nice if you could since it would also provide some guarantee
of it being a fairly stable interface.

The other function that I saw get usage outside of nadvice and bytecomp
was advice--symbol-function.  Should we use its return value, or is
indirect-function's return value good enough for advice--cd*r?  IIRC,
help-function-arglist uses indirect-function and it also works for our
use case.

>> though it might be that we (Visuwesh and I) are trying to do the wrong
>> thing, since we want the return value to get a more sensible response
>> from `func-arity' -- and I recall we had conversations about the
>> complexity of this issue in the past before.
>
> There are very few places where `func-arity` can be used reliably,
> indeed and most of those cases are better served by
> `help-function-arglist`.
>
> In the case where `func-arity` is used for backward compatibility
> purposes (where reliability is not really possible anyway), I've
> generally recommend the use of
>
>     (condition-case nil
>         ...
>       (wrong-number-of-aruments
>         ...))
>
> instead.  It comes with its own failure modes, of course, but it's
> usually easier to use and I found it to fail less often in practice
> (because it's not affected by wrappers like those introduced by advice
> or `apply-partially`).
>
>
>         Stefan