[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Circular structure printing



InterLisp has had HPRINT for some time, which among other things prints out
circular structure in a "readable" fashion.  Having a separate function for this
purpose, rather than a Global variable flag which affects PRINT, may be a better
route as long as the PRIN1/PRINC dichotomy remains.  Unfortunately, this means
that every place where the PRIN1/PRINC dichotomy appears will not have to
become a PRIN1/PRINC/PRINH trichotomy (e.g., such as in EXPLODE and
PRIN?-TO-STRING). 

Efficiency in HPRINT is obtained by looking for circularities in a hash table,
and either 1) for randomly-accessible files doing the equivalent of a
FILE-POSITION to go back and insert a macro character in front of the
"first" occurrence, or 2) otherwise just printing to a "temporary, in-core"
file and then unloading the temproary file to the real output file.   This
code is, I think, in the public domain, so you could look at it if you still
want to;  printing to a "temporary" file is of course equivalent to SEF's 
suggestion to print first to a string.   [by the bye, HPRINT stands for 
"Horrible PRINT" since it handles all the horrible cases].

LISP/370 had a printer which did circularities right.   It was my subjective,
non-documented, feeling that there was no discernible time loss in this code; 
but then again it used 370 machine language and, depended upon having an
alternate "heap" to use as a hash table.   Might be nice to know what some
of the purely-Lisp written printers cost in time.

Beau Sheil noted an interesting comment about the reference-count GC
scheme of InterLisp-D:  since it's primarly structure-to-structure pointers
that are reference-counted (not local variables or stack slots), then a quick,
generally-useful, and fail-safe test for non-circularity is merely a bittest from
the GC table.  This is not how HPRINT is implemented, since it runs on the
PDP10 too, but is an interesting observation about the effects of GC strategy.