From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Lars Brinkhoff Newsgroups: gmane.emacs.help Subject: Object identity Date: 21 Oct 2003 08:07:57 +0200 Organization: nocrew Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <8565ijazsy.fsf@junk.nocrew.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1066716635 12718 80.91.224.253 (21 Oct 2003 06:10:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 21 Oct 2003 06:10:35 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 21 08:10:32 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ABpix-0005WM-00 for ; Tue, 21 Oct 2003 08:10:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1ABphD-0007JV-IP for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Oct 2003 02:08:43 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1ABph2-0007JO-SM for help-gnu-emacs@gnu.org; Tue, 21 Oct 2003 02:08:32 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1ABpgW-0007AG-8J for help-gnu-emacs@gnu.org; Tue, 21 Oct 2003 02:08:31 -0400 Original-Received: from [213.242.147.30] (helo=junk.nocrew.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1ABpgV-0007A8-UU for help-gnu-emacs@gnu.org; Tue, 21 Oct 2003 02:08:00 -0400 Original-Received: from lars by junk.nocrew.org with local (Exim 3.35 #1 (Debian)) for help-gnu-emacs@gnu.org id 1ABpgT-0000UW-00; Tue, 21 Oct 2003 08:07:57 +0200 Original-To: help-gnu-emacs@gnu.org Original-Lines: 31 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:13402 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:13402 (Would emacs-devel be a more appropriate list to post this?) Is there a function, say object-identity, in Emacs Lisp that maps an object to a unique value (other than the object itself)? For example, the value could be an integer, or a list of integers, or a string, that represents the memory address of the object. To clarify, this function would have the property that (equal (object-identity obj1) (object-identity obj2)) if and only if (eq obj1 obj2) . This is my current implementation. However, my version of Emacs doesn't implement weak hash tables, so it will make memory leak. Any ideas about how to deal with that? (defvar object-identities (make-hash-table :test 'eq :weakness t)) (defvar identity-counter 0) (defun object-identity (object) (or (gethash object object-identities) (setf (gethash object object-identities) (incf identity-counter)))) (Yes, I'm aware the counter will eventually wrap around...) -- Lars Brinkhoff, Services for Unix, Linux, GCC, HTTP Brinkhoff Consulting http://www.brinkhoff.se/