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 07:54:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> CL-USER> (funcall (list 'lambda nil 42))
> 42 (6 bits, #x2a, #o52, #b101010)
> CL-USER> (functionp (list 'lambda nil 42))
> NIL

That matches where I'd like ELisp to be 🙂

> But then there's the common pattern in libraries:
>
>   (let ((value (if (functionp user-visible-variable)
>                    (funcall user-visible-variable)
>                  user-visible-variable)))
>     ...)
>
> Won't this break a user's config containing:
>
>   (setq user-visible-variable '(lambda () 42))
>
> ?

Yup.  My impression is that this is sufficiently rare that we can afford
to break it.  Maybe experience will show me wrong, of course.
We could also consider an intermediate step where `functionp` returns
t but emits a warning.

> You can't forbid (funcall (list 'lambda)) without breaking lots of
> user code,

That's my impression, indeed.

> That's if you're interested in fixing this bit at all, which you don't
> seem to be.

I don't see very much benefit from forbidding (funcall (list 'lambda)),
indeed.  From a purely philosophical point of view, I agree that it
should not be accepted, but in practice the only downsides I can see are:

- it can give a wrong impression to a beginner, encouraging confusion.
- it can occasionally hide an error, making debugging a bit more difficult.

These seem very marginal to me.


        Stefan




reply via email to

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