emacs-devel
[Top][All Lists]
Advanced

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

Re: Distinguishing `consp` and `functionp`


From: Stefan Monnier
Subject: Re: Distinguishing `consp` and `functionp`
Date: Tue, 30 Jan 2024 18:13:20 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

>> Yup.  My impression is that this is sufficiently rare that we can afford
>> to break it.  Maybe experience will show me wrong, of course.
>
> I've definitely seen users post configs to Eglot's bug tracker where
> lambdas appear incorrectly quoted.  i.e.
>
>   (add-to-list 'eglot-server-programs '(foo-mode . (lambda (..) ...)))

Yes, that's very common and that's why I don't think we can drop support
for that in `funcall`.  What I hope is less common is for those cases
to go through `functionp`.

Of course, it also depends on happenstance of how the `functionp` test
is written.  E.g. for `eglot-server-programs` it seems that we
will/would suffer because we start by testing `functionp` instead of
first handling the non-function-like lists.

>> We could also consider an intermediate step where `functionp` returns
>> t but emits a warning.
> Indeed, though in that case I'd make the funcall warn. I think it's there
> that this proposed runtime warning  ultimately matters and is useful
> to help users correct their elisp. Runtime warnings are a bit icky though
> :-| but better than nothing.

We already have compile time warnings at those places where the compiler
easily knows that the list should be a function, but for all those other
cases (like `eglot-server-programs`), we don't have any tool currently
other than run-time warnings.

>> - it can give a wrong impression to a beginner, encouraging confusion.
>> - it can occasionally hide an error, making debugging a bit more difficult.
> Wouldn't you add "complicates type propagation, static analysis and
> optimization" to that list?

No.  All these can be blissfully unaware of what `funcall` does when
presented with a list starting with `lambda`.  In theory, it's true that
analysis&optimization could assume that *after* the `funcall` the
argument was a valid function obeying `functionp`, but I suspect our
analysis/optimization technology is pretty far from that level, and even
if we were able to make that work, the potential for gains from such
information seems vanishingly small.


        Stefan




reply via email to

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