From: arthur miller <arthur.miller@live.com>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Sv: Subrp returns nil for function objects and symbols? Is this a bug or me misunderstanding it?
Date: Tue, 13 Aug 2024 18:00:12 +0000 [thread overview]
Message-ID: <DU2PR02MB10109B440C10DF844887FCABA96862@DU2PR02MB10109.eurprd02.prod.outlook.com> (raw)
In-Reply-To: <87h6bo8yta.fsf@gmx.net>
[-- Attachment #1: Type: text/plain, Size: 3545 bytes --]
> > (subrp 'car) => nil
> > (subrp #'car) => nil
> > (subrp '+) => nil
> >
> > (subrp (symbol-function 'car)) => t
> >
> > According to the doc, subrp should tell me if "OBJECT" is a built-in
> > function or not. I would expect "car" to be that, since car is implemented
> > in the C source (in data.c).
> >
> > I also get the same behavior for compiled-function-p.
> >
> > Is it not valid to pass a symbol and function objects to those two
> > functions? Can we in that case clarify in the doc string expected
> > value(s) for OBJECT?
>
> At least it's documented in the Elisp manual (info "(elisp) What Is a
> Function"):
Yes. I see it now. I was just looking at function docs previously. Thanks.
> Unlike ‘functionp’, the next functions do _not_ treat a symbol as its
> function definition.
>
> -- Function: subrp object
> This function returns ‘t’ if OBJECT is a built-in function (i.e., a
> Lisp primitive).
>
> (subrp 'message) ; ‘message’ is a symbol,
> ⇒ nil ; not a subr object.
> (subrp (symbol-function 'message))
> ⇒ t
Ok, they are explicit it does not look at function slot of a symbol itself
(2.4.15). However, I find the documentation a bit vague or perhaps outdated. In
particular regarding the "built-in" type. Perhaps this function
historically meant something else than how it works today (I think it did). I
guess built-in used to mean "implemented in C core", but since the native
compiler come in, it seems to rapport any machine-code compiled function as
"subr":
(defun test-fn () (message "hi"))
(native-compile 'test-fn)
(subrp (symbol-function 'test-fn)) => t
In other words, perhaps manual should be updated to say something along the line
that subrp tells if function is a function compiled to machine code. I see now
also that compiled-function-p repports if a function is both byte-code compiled
and machine-code compiled as "compiled" so those are not equal.
________________________________
Från: Stephen Berman <stephen.berman@gmx.net>
Skickat: den 13 augusti 2024 13:08
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Subrp returns nil for function objects and symbols? Is this a bug or me misunderstanding it?
On Tue, 13 Aug 2024 09:22:01 +0000 arthur miller <arthur.miller@live.com> wrote:
> (subrp 'car) => nil
> (subrp #'car) => nil
> (subrp '+) => nil
>
> (subrp (symbol-function 'car)) => t
>
> According to the doc, subrp should tell me if "OBJECT" is a built-in
> function or not. I would expect "car" to be that, since car is implemented
> in the C source (in data.c).
>
> I also get the same behavior for compiled-function-p.
>
> Is it not valid to pass a symbol and function objects to those two
> functions? Can we in that case clarify in the doc string expected
> value(s) for OBJECT?
At least it's documented in the Elisp manual (info "(elisp) What Is a
Function"):
Unlike ‘functionp’, the next functions do _not_ treat a symbol as its
function definition.
-- Function: subrp object
This function returns ‘t’ if OBJECT is a built-in function (i.e., a
Lisp primitive).
(subrp 'message) ; ‘message’ is a symbol,
⇒ nil ; not a subr object.
(subrp (symbol-function 'message))
⇒ t
Steve Berman
[-- Attachment #2: Type: text/html, Size: 10774 bytes --]
next prev parent reply other threads:[~2024-08-13 18:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 9:22 Subrp returns nil for function objects and symbols? Is this a bug or me misunderstanding it? arthur miller
2024-08-13 11:08 ` Stephen Berman
2024-08-13 18:00 ` arthur miller [this message]
2024-08-14 10:08 ` Sv: " Stephen Berman
2024-08-15 9:01 ` Andrea Corallo
2024-08-15 16:37 ` Sv: " arthur miller
2024-08-15 18:58 ` arthur miller
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=DU2PR02MB10109B440C10DF844887FCABA96862@DU2PR02MB10109.eurprd02.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
--cc=stephen.berman@gmx.net \
/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).