GNU bug report logs -
#69739
30.0.50; `type-of` is not precise enough
Previous Next
Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>
Date: Mon, 11 Mar 2024 23:22:01 UTC
Severity: normal
Found in version 30.0.50
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: basil <at> contovou.net, acorallo <at> gnu.org, 69739 <at> debbugs.gnu.org
> 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?
This bug report was last modified 1 year and 120 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.