Subject: bug#69739: 30.0.50; `type-of` is not precise enough

From: Eli Zaretskii <[email-masked]>
Date: Mon, 18 Mar 2024 14:56:58 +0200

> From: Stefan Monnier <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Sun, 17 Mar 2024 18:29:10 -0400
> 
> > Yes, I think we should document it near type-of, as the explanation
> > when and why to prefer cl-type-of is quite simple and easily
> > understandable.
> 
> OK, here's a new (set of) patches (also available in the
> `scratch/object-type` branch).  I added the doc as well as a test
> (which pointed to the `subr-primitive-p` problem), and an additional
> hunk which fixes the `subr-primitive-p`.

Thanks, a few nits below.

> +@defun cl-type-of object
> +This function returns a symbol naming @emph{the} type of
> +@var{object}.  It usually behaves like @code{type-of}, except
> +that it guarantees to return the most precise type possible, which also
> +implies that the specific type it returns may change depending on the
> +Emacs version.  For this reason, as a rule you should never compare its
> +return value against some fixed set of types.
> +
> +@example
> +(object-type 1)
> +     @result{} fixnum
> +@group
> +(object-type 'nil)
> +     @result{} null
> +(object-type (record 'foo))
> +     @result{} foo

"object-type"?

>  DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
>         doc: /* Return a symbol representing the type of OBJECT.
>  The symbol returned names the object's basic type;
> -for example, (type-of 1) returns `integer'.  */)
> +for example, (type-of 1) returns `integer'.
> +Contrary to `cl-type-of' the returned type is not always the most
                          ^^
I think we want a comma there.
> +DEFUN ("cl-type-of", Fcl_type_of, Scl_type_of, 1, 1, 0,
> +       doc: /* Return a symbol representing the type of OBJECT.
> +The symbol returned names the most specific possible type of the object.
   ^^^^^^^^^^^^^^^^^^^
I think "The returned symbol" is better here, as it prevents a
possible confusion (whether "returned" alludes to "symbol" or to
"names").

> +for example, (object-type nil) returns `null'.
                 ^^^^^^^^^^^
"object-type"?

>  (defsubst subr-primitive-p (object)
> -  "Return t if OBJECT is a built-in primitive function."
> +  "Return t if OBJECT is a built-in primitive written in C."
>    (declare (side-effect-free error-free))
>    (and (subrp object)
>         (not (subr-native-elisp-p object))))
>  
> +(defsubst primitive-function-p (object)
> +  "Return t if OBJECT is a built-in primitive function."
> +  (declare (side-effect-free error-free))
> +  (and (subrp object)
> +       (not (or (subr-native-elisp-p object)
> +                (eq (cdr (subr-arity object)) 'unevalled)))))

Should these doc strings mention the special case of special form,
which each one of them treats differently?