emacs-devel
[Top][All Lists]
Advanced

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

Re: Distinguishing `consp` and `functionp`


From: João Távora
Subject: Re: Distinguishing `consp` and `functionp`
Date: Mon, 29 Jan 2024 15:54:04 +0000

On Mon, Jan 29, 2024 at 3:42 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> > And the reason(s) you are "annoyed at the use of lists to represent
> > function values" are?...  IOW, what will we gain by using your changes
> > in this matter?
>
> Beside taste and philosophical differences, the main motivation is to
> make `consp` and `functionp` mutually exclusive so as to eliminate the
> risk that a list be considered mistakenly as a function or vice versa.

I don't think there is much space for philosophy or debate in noting
for example, that a list as lambda won't get byte-compiled like a
true lambda form.

(byte-compile '(let ((bla (lambda () (+ 42 42))))
                 (funcall bla))) ;; -> (byte-code "\300\211 \207" [#[0
"\300\207" [84] 1]] 2)


(byte-compile '(let ((bla '(lambda () (+ 42 42))))
                 (funcall bla)));; -> (byte-code "\300 \207" [(lambda
nil (+ 42 42))] 1)

> I mentioned that this risk of confusion is the reason why our completion
> functions do not officially support completion tables represented as
> lists of symbols (even though in practice they work fine (except when
> the first symbol happens to be `lambda` or `closure`)).
>
> It also occurs in various other places where we want to allow either
> a function or a list.
>
> E.g. a recent bugfix in YASnippet:
>
>     commit 9228fd983bb9e71d44d406433a46495b22640801
>     Author: Marten Lienen <marten.lienen@gmail.com>
>     Date:   Mon Jan 22 11:08:44 2024 +0100
>
>         * yasnippel.el (yas-buffer-local-condition): Check functionp before 
> consp to allow closures
>

Yup, thank you very much for that.

Stefan's patch moves us in the right direction if just for the guidance
it gives to ignorant Lispers like the one who introduced that bug circa 2009.

João



reply via email to

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