Re: printing recursive objects?

"John Lacey" <johnl@cs.indiana.edu>
Tue, 4 May 1993 06:46:40 GMT

          From comp.compilers

Related articles
printing recursive objects? haahr@mv.us.adobe.com (Paul Haahr) (1993-05-03)
Re: printing recursive objects? johnl@cs.indiana.edu (John Lacey) (1993-05-04)
printing recursive objects? ontos!tonyk@uu.psi.com (Tony Kanawati) (1993-05-04)
printing recursive objects? davis@ilog.ilog.fr (1993-05-05)
| List of all articles for this month |
Newsgroups: comp.compilers
From: "John Lacey" <johnl@cs.indiana.edu>
Keywords: Lisp
Organization: Computer Science, Indiana University
References: 93-05-014
Date: Tue, 4 May 1993 06:46:40 GMT

Paul Haahr <haahr@mv.us.adobe.com> writes:


> For example, given the scheme expression
>
> (let ((x (cons 'a nil))) (set-cdr! x x) x)
>
> how do I print some scheme expression that, when interpreted,
> creates the same structure, rather than just a lot of ``a''s?


Chez Scheme has a parameter called print-graph. When enabled, write prints
objects in a notation which may be read in later. (Of course, this
requires the cooperation of read, as well.)


The notation is that the first occurence of a duplicated object is written
as `#n=object', and subsequent occurences of the object are written as
`#n#'. Your example would be printed as `#0=(a . #0#)'.


Of course a simple table lookup will suffice to detect duplicated objects.
I don't, unfortunately, have any references, or knowledge of more
complicated algorithms, if such exist. (The description in the Chez System
Manual is no more detailed than that the above.)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.