emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should `indirect-function' be preferred over `fboundp'?


From: Alan Mackenzie
Subject: Re: Should `indirect-function' be preferred over `fboundp'?
Date: Thu, 20 Jul 2023 13:02:34 +0000

Hello, Ihor.

On Thu, Jul 20, 2023 at 07:08:48 +0000, Ihor Radchenko wrote:
> Hi,

> I have recently stumbled upon the common Elisp pattern
> (when (fboundp func) (funcall func)) failing.

> This is happening when a symbol is declared as function alias to
> non-existing function:

> (defalias 'yant/foo 'yant/bar)
> (fboundp 'yant/foo) ; => t
> (funcall 'yant/foo) ; => ERROR: Symbol function definition is void: yant/foo

I don't think it affects the point you are making, but why are you using
funcall in the last line, rather than just calling the funcion as

  (yant/foo)

?  I initially got confused and thought you were doing

  (funcall yant/foo)

, which would have been an obvious error.

> In contrast, `indirect-function' does a better job determining whether a
> given symbol can be called as a function:

> (indirect-function 'yant/foo) ; => nil

> Is it something widely known?
> Is it something to worry about?
> (I can see that `fboundp' is used all over Emacs git sources, while
> `indirect-function' is rarely used)

> -- 
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]