From: Donald H. Mitchell
Subject: Re: Uniquely identifying objects in Lisp
Date: 
Message-ID: <52uabq$4lt@dropit.pgh.net>
In article <··········@bark.cs.utexas.edu>, ·······@cs.utexas.edu (Michael Alan Schaeffer) wrote:
> ... graph ... traverse my data structure...depict shared
>structure as shared.  To do this, I need to be able to assign a unique
>identifier to each object (probably based on memory location).

If I understand your query, you don't need to do anything. Lisp does it for 
you already via #'eq.   That is, unless you absolutely want to print out your 
uniqueno rather than merely detect shared structure.  Remember in Lisp, shared 
structure is truly shared not copied nor indirect.

Thus in your example,

>> (setf a '(2 . 3))
>(2 . 3)
>
>> (setf b (cons 1 a)
>(1 2 . 3)

(eq a b) => nil
(eq a (cdr b)) => t
(setf (cdr a) 4) => 4
b => (1 2 . 4) ;b/c it shares w/ a and any changes to a thus show up in b.

OTOH, When traversing a non-tree graph in which I want to ensure I don't visit 
the same node twice, I usually use a hash table to store the visited nodes.  I 
suppose if you want a uniqueid, you could use sxhash or generate and store 
an id (e.g., sequential # or gensym) in a hashtable. (Of course, sxhash is not 
guaranteed unique, just nearly so.)

Donald H. Mitchell              ···@pgh.net
Proactive Solutions, Inc.       412.835.2410
5858 Horseshoe Dr.              412.835.2411 (fax)
Bethel Park, PA 15102