From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 69739@debbugs.gnu.org
Cc: monnier@iro.umontreal.ca
Subject: bug#69739: 30.0.50; `type-of` is not precise enough
Date: Mon, 11 Mar 2024 19:19:40 -0400 [thread overview]
Message-ID: <jwvr0ggmk4z.fsf@iro.umontreal.ca> (raw)
Package: Emacs
Version: 30.0.50
`type-of` is supposed to return "the" type of its argument. Given that
ELisp has a notion of subtyping, "the" type is expected to mean "the
most precise type". This is used in `cl-generic` to decide which method
to apply, so it's important that it returns precise information.
Currently, there `type-of` fails to return precise enough information in
a few cases:
- When the argument is nil, it returns `symbol`. The problem here is
that `symbol` is not a subtype of `list`, whereas nil is a list.
- When the argument is a special form, a C primitive, or
a native-compiled function it returns `subr`. Currently our
type hierarchy says that `subr` is a subtype of `compiled-function`
(and hence of `function`), but a special form is *not* a function
(it fails the `functionp` test and can't be `funcall`ed).
Currently `cl-generic` works around the first point above by using
(if FOO (type-of FOO) 'null) instead of calling `type-of` directly.
Suggestion:
I suggest we change `type-of` to return `null` for `nil`,
`special-form` for subrs that are special forms, `subr-primitive`
for C primitives, and `subr-native-elisp` for native-compiled subrs.
There are a few other cases where we could improve the precision, tho
they are less important because they don't cause problems w.r.t
subtyping like the above does.
Further improvements could include:
- Return `boolean` for `t`. This would be nice otherwise (with the
above suggestion) `cl-generic` can dispatch on "nil is a boolean"
but not on "t is a boolean".
- Return `keyword` for symbols that are keywords.
- Return `fixnum` or `bignum` rather than just `integer`.
Probably not worth the trouble.
- We could go crazy and return `keyword-with-pos` for `symbols-with-pos`
that are keywords.
Of these further improvements, only the first (return `boolean` for `t`)
seems worth the trouble.
Still, any change as suggested here would be an incompatible change, so
there's risk it'll break some code out there (`type-of` is not used very
often, but it *is* used). Another option is to introduce a new function
which does the same as `type-of` but with changes like the ones above.
(we could even decide to give it a `cl-generic-` prefix to discourage
its use elsewhere so we can be more free to change its return value in
the future).
Stefan
next reply other threads:[~2024-03-11 23:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 23:19 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-03-12 13:37 ` bug#69739: 30.0.50; `type-of` is not precise enough Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-12 14:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-12 16:07 ` Rudolf Schlatte
2024-03-13 22:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-12 13:58 ` Eli Zaretskii
2024-03-12 14:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-12 15:02 ` Eli Zaretskii
2024-03-12 15:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-13 11:55 ` Eli Zaretskii
2024-03-14 16:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-15 9:42 ` Andrea Corallo
2024-03-15 10:54 ` Andrea Corallo
2024-03-15 9:51 ` Basil L. Contovounesios
2024-03-15 14:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-15 15:18 ` Eli Zaretskii
2024-03-17 22:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-18 12:56 ` Eli Zaretskii
2024-03-18 13:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-15 11:50 ` Eli Zaretskii
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvr0ggmk4z.fsf@iro.umontreal.ca \
--to=bug-gnu-emacs@gnu.org \
--cc=69739@debbugs.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).