In article <··········@bark.cs.utexas.edu> ·······@cs.utexas.edu (Michael Alan Schaeffer) writes:
> Hello, I'm trying to develop a system for graphically
> displaying Lisp data structures. I already have access to a program
> that can take a textual representation of a graph and display it
> graphically. What I want to do then, is to traverse my data structure
> in Lisp, and write out one of these descriptions. So far so good.
> The problem is that I want to be able to 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).
This should be pretty easy to program yourself. You will definitely NOT
want to use a scheme based on memory location because most modern
garabage collectors are copying collectors and move objects around in
memory. The memory address of an object in Lisp is not static!
I would suggest just using a counter and a hash table. This takes
advantage of the fact that Lisp's EQ test really is a test for object
identity.
> Ideally it would work like this:
>
>> (setf a '(2 . 3))
> (2 . 3)
>
>> (setf b (cons 1 a)
> (1 2 . 3)
>
>> (uniqueno a)
> 123
>
>> (uniqueno b)
> 456
>
>> (uniqueno (cdr b))
> 123
For example:
(defvar *counter* 0)
(defvar *unique-hashtable* (make-hash))
(defun uniqueno (object)
(or (gethash object *unique-hashtable*)
(setf (gethash object *unique-hashtable*) (+ *counter* 1))))
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu
In article <···············@hobbes.isi.edu> ···@ISI.EDU (Thomas A. Russ) writes:
> For example:
>
> (defvar *counter* 0)
> (defvar *unique-hashtable* (make-hash))
>
> (defun uniqueno (object)
> (or (gethash object *unique-hashtable*)
> (setf (gethash object *unique-hashtable*) (+ *counter* 1))))
^^^^^^^^^^^^^^^
(incf *counter*)
As my old acquaintance Sam Pilato pointed out to me in EMail, this needs
to be fixed.
-Tom.
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu