diff --git a/doc/lispref/hash.texi b/doc/lispref/hash.texi index 8389c21..6ee18d6 100644 --- a/doc/lispref/hash.texi +++ b/doc/lispref/hash.texi @@ -307,6 +307,16 @@ and equal-looking objects are considered the same key. (make-hash-table :test 'contents-hash) @end example address@hidden xhash obj +This function returns a hash code for Lisp object @var{obj}. Its +result reflects identity of @var{obj}, but not its contents. + +If two objects @var{obj1} and @var{obj2} are @var{eq}, then address@hidden(xhash @var{obj1})} and @code{(xhash @var{obj2})} are the same +integer. address@hidden defun + + @node Other Hash @section Other Hash Table Functions diff --git a/etc/NEWS b/etc/NEWS index 66777e9..146c756 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -208,6 +208,12 @@ permanent and documented, and may be used by Lisp programs. Its value is a list of currently open parenthesis positions, starting with the outermost parenthesis. ++++ +** New function 'xhash' returns identity hash code of a Lisp object. +If two objects are 'eq', then the result of 'xhash' on them will be +the same. In other words, this function to 'eq' is the same as +'sxhash' is to 'equal'. + * Changes in Emacs 25.2 on Non-Free Operating Systems diff --git a/src/fns.c b/src/fns.c index 114a556..a1cf2b1 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4449,6 +4449,16 @@ sxhash (Lisp_Object obj, int depth) ***********************************************************************/ +DEFUN ("xhash", Fxhash, Sxhash, 1, 1, 0, + doc: /* Compute identity hash code for OBJ and return it as integer. +In other words, hash codes of two non-`eq' lists will be (most likely) +different, even if the lists contain the same elements. */) + (Lisp_Object obj) +{ + return make_number (XHASH (obj)); +} + + DEFUN ("sxhash", Fsxhash, Ssxhash, 1, 1, 0, doc: /* Compute a hash code for OBJ and return it as integer. */) (Lisp_Object obj) @@ -5067,6 +5077,7 @@ syms_of_fns (void) DEFSYM (Qkey_or_value, "key-or-value"); DEFSYM (Qkey_and_value, "key-and-value"); + defsubr (&Sxhash); defsubr (&Ssxhash); defsubr (&Smake_hash_table); defsubr (&Scopy_hash_table);