all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Distinguishing `consp` and `functionp`
Date: Tue, 30 Jan 2024 23:43:38 +0000	[thread overview]
Message-ID: <CALDnm51Qj-=JK0bd=MjDq5DweBG2s18k0kFY2vHjOxxchG5xHw@mail.gmail.com> (raw)
In-Reply-To: <jwvjznqmnsj.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3350 bytes --]

On Tue, Jan 30, 2024 at 11:13 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

  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.

Yeah but, I could fix that if I had a time machine :-)
Anyway I tend to think it makes the code simpler to get that functionp case
out of the way first and it doesn't seem I'm alone.  Have you grepped for
the
words "can also be a function" ? It sure seems to suggest many many others
do the same: start by calling functionp.  Won't they _all_ be broken if
users
have been putting lists in those user vars by mistake?

> >> 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.

Of course.  What I'm saying is basically.

* Do this patch, it's probably a good step.
* keep functionp returning t for those lists for a while (say one major
version)
  to avoid too much fallout.
* warn at runtime in the funcall.  Then users using these problematic
customizations will start fixing  their code. We'll probably catch some
library doing this too.

One thing it'd be nice to have for runtime warnings is some kind of
file location hint.  Maybe check the calling frame?

> >> - 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.

Dunno.  SBCL's compiler is pretty good, it propagates types  and warns
say, when using generic+ instead of must faster fixum+.  You can really
extract  some good perf from it.  Our byte-compiler is not advanced enough?
Maybe.  But what about the native compiler?  And shouldn't we be making
way for these advances.

All in all, I can't see how these fishy funcalls don't amount to anything
other than 'eval' in disguise. And though I'm admittedly not as expert in
this field as you are, I've always learned  'eval' is known to be nono
because of these and other pitfalls.  See e.g. this very good Rainer Joswig
answer https://stackoverflow.com/a/2571549 (I'm aware you're probably
aware of those arguments, just mentioned for others who may be interested).

João

[-- Attachment #2: Type: text/html, Size: 4010 bytes --]

  reply	other threads:[~2024-01-30 23:43 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-25 23:15 Distinguishing `consp` and `functionp` Stefan Monnier
2024-01-26  0:00 ` Adam Porter
2024-01-26  0:24   ` Stefan Monnier
2024-01-26  7:31 ` Eli Zaretskii
2024-01-26 19:22   ` João Távora
2024-01-26 21:13     ` Stefan Monnier
2024-01-26 21:50       ` João Távora
2024-01-26 23:55         ` Stefan Monnier
2024-01-27  0:22           ` Daniel Mendler via Emacs development discussions.
2024-01-27 11:47             ` João Távora
2024-01-27 13:20             ` Po Lu
2024-01-27 11:53           ` João Távora
2024-01-28  3:03           ` Richard Stallman
2024-01-28 21:27   ` Stefan Monnier
2024-01-29 12:45     ` Eli Zaretskii
2024-01-29 15:19       ` Stefan Monnier
2024-01-29 15:31         ` Eli Zaretskii
2024-01-29 15:41           ` Stefan Monnier
2024-01-29 15:46             ` Eli Zaretskii
2024-01-29 15:48               ` Stefan Monnier
2024-01-29 15:54             ` João Távora
2024-01-29 16:10               ` Eli Zaretskii
2024-01-29 16:25                 ` João Távora
2024-01-29 16:10               ` Eli Zaretskii
2024-01-29 16:17               ` Andreas Schwab
2024-01-29 16:34                 ` João Távora
2024-02-01  3:49                   ` Richard Stallman
2024-01-29 16:28               ` Stefan Monnier
2024-01-29 16:34                 ` João Távora
2024-01-29 20:00                   ` Stefan Monnier
2024-01-30  8:58                     ` João Távora
2024-01-30 12:54                       ` Stefan Monnier
2024-01-30 22:24                         ` João Távora
2024-01-30 23:13                           ` Stefan Monnier
2024-01-30 23:43                             ` João Távora [this message]
2024-01-31  0:22                               ` Stefan Monnier
2024-01-31  0:40                                 ` João Távora
2024-01-31  3:37                                   ` Stefan Monnier
2024-01-31 10:51                                     ` João Távora
2024-01-31 18:34                                       ` Stefan Monnier
2024-02-01  3:49                   ` Richard Stallman
2024-01-29 17:09             ` Yuri Khan
2024-02-01  3:49             ` Richard Stallman
2024-01-30  3:58     ` Richard Stallman
2024-01-27 11:00 ` Alan Mackenzie
2024-01-27 14:25   ` Stefan Monnier
2024-01-27 23:01     ` Alan Mackenzie
2024-01-28  0:00       ` Stefan Monnier
2024-01-28  6:12         ` Eli Zaretskii
2024-01-28 17:26         ` Alan Mackenzie
2024-01-28 17:48           ` Eli Zaretskii
2024-01-28 19:42             ` Alan Mackenzie
2024-01-28 20:08               ` Eli Zaretskii
2024-01-28 18:21           ` Stefan Monnier
2024-01-28 18:38           ` Stefan Monnier
2024-01-27 13:14 ` Po Lu
2024-01-27 14:41   ` Stefan Monnier
2024-01-28  1:56     ` Po Lu
2024-01-28 20:55     ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALDnm51Qj-=JK0bd=MjDq5DweBG2s18k0kFY2vHjOxxchG5xHw@mail.gmail.com' \
    --to=joaotavora@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.