unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69832: 30.0.50; Should `subr-primitive-p` apply to special-forms?
@ 2024-03-16 19:30 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-03-16 19:45 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-03-16 19:30 UTC (permalink / raw)
  To: 69832; +Cc: monnier

Package: Emacs
Version: 30.0.50


Currently (subr-primitive-p (symbol-function 'if)) returns t.
Its docstring disagrees:

    Return t if OBJECT is a built-in primitive function.

because `if` is indeed a "built-in primitive" but not a "function" (you
can't `funcall` it and it is rejected by `functionp`: it's a special
form instead).

For ELisp's type hierarchy/DAG we need a type for "a built-in primitive
which is also a function".  Originally, based on the docstring,
I thought I could use `subr-primitive`.
But it turns out that the code doesn't quite match the docstring.

I can see two ways to fix that:

- Introduce a new type, says `subr-function(-p)` which returns non-nil
  if and only if the argument is a built-in primitive *and* a function.

- Change the implementation of `subr-primitive-p` to match its docstring.

The patch below does the second (including changing the only place
I found that wants the current semantics.

Comments?  Objections?


        Stefan


diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 411602ef166..3458ace1c08 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -552,7 +552,7 @@ find-function-library
     (cons function
           (cond
            ((autoloadp def) (nth 1 def))
-           ((subr-primitive-p def)
+           ((or (subr-primitive-p def) (special-form-p def))
             (if lisp-only
                 (error "%s is a built-in function" function))
             (help-C-file-name def 'subr))
diff --git a/lisp/subr.el b/lisp/subr.el
index 38a3f6edb34..f403369f534 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -315,7 +315,8 @@ subr-primitive-p
   "Return t if OBJECT is a built-in primitive function."
   (declare (side-effect-free error-free))
   (and (subrp object)
-       (not (subr-native-elisp-p object))))
+       (not (or (subr-native-elisp-p object)
+                (special-form-p object)))))
 
 (defsubst xor (cond1 cond2)
   "Return the boolean exclusive-or of COND1 and COND2.






^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-17 21:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-16 19:30 bug#69832: 30.0.50; Should `subr-primitive-p` apply to special-forms? Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-16 19:45 ` Eli Zaretskii
2024-03-16 19:58   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-16 20:17     ` Eli Zaretskii
2024-03-16 23:08       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-17  6:01         ` Eli Zaretskii
2024-03-17 21:03           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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