[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#32503: 26.1; Byte-compiled functions don't hash consistently
From: |
Adam Porter |
Subject: |
bug#32503: 26.1; Byte-compiled functions don't hash consistently |
Date: |
Wed, 22 Aug 2018 14:00:28 -0500 |
I noticed that byte-compiled functions don't hash consistently. Here's
an ECM from Noam Postavsky
<https://github.com/skeeto/emacs-memoize/pull/10#issuecomment-415066682>:
(let ((obj1 (byte-compile (lambda (x) x)))
(obj2 (byte-compile (lambda (x) x))))
(list (equal obj1 obj2)
(eq obj1 obj2)
(= (sxhash obj1)
(sxhash obj2))))
;=> (t nil nil)
According to "(elisp) Defining Hash":
If two objects OBJ1 and OBJ2 are equal, then ‘(sxhash OBJ1)’ and
‘(sxhash OBJ2)’ are the same integer.
This makes it impossible to use byte-compiled functions as keys or parts
of keys in hash tables. A workaround is to `prin1-to-string` the
byte-compiled function and use that as the key.
Thanks.
- bug#32503: 26.1; Byte-compiled functions don't hash consistently,
Adam Porter <=