From within Neovim, I can execute the command
:lua print(vim.fn.non_existent_function), and would get something like
function: 0x01052bc2a8 as the printed output. But of course, if I were to actually call this function like
:lua vim.fn.non_existent_function(), I'd get the following error message:
E5108: Error executing lua Vim:E117: Unknown function: non_existent_function stack traceback: [C]: in function 'non_existent_function' [string ":lua"]:1: in main chunk
My guess is Neovim probably implemented this in a manner such that any member of the
vim.fn table is automatically deemed to be a function, and its actual existence or lack thereof is only truly known when it is being called and passed onto its Vim counterpart. But please correct me if this is incorrect or inaccurate.
My main question is, why was it chosen to be like this? Does it not make more sense for non-existent keys to be
nil in their corresponding value?
I discovered this when trying to check for the existence of a Vim/Neovim built-in function. But because
vim.fn.non_existent_function is not
nil, which is what I originally expected, that approach was not viable.