At 11:26 -0800 1999/11/30, Mark P Jones wrote:
>..In summary,
>the Hugs printer ends up displaying part of one of the dictionaries that
>(a) are used in the implementation of overloading, and (b) contain cyclic
>structures. Some parts of the implementation have changed a little since
>then, but the underlying principles are still the same.
>
>Perhaps Hugs could be made to abort the display of an error message beyond
>a certain number of characters or depth ... folks might still be confused
>by the output, but at least it won't take forever to display ...
One can write a program that writes out references, including the cyclic
structures, too (but it does not help with large printouts). I did it when
working on an object oriented runtime model that understands lambda
calculus.
For example, suppose one has
f = [sqrt, sqrt, f]
where both "f" and both "sqrt" happens to be references to the same
internal object (so the "f" within the list points to the whole of the
list), then the printout would be (with a natural scanning order from the
outmost towards the innermost objects)
0: [:1, :1, :0]
1: sqrt
Thus, all internal references can be displayed, including loops.
I did this by first scanning subobjects in the natural order my model gave
them, marking each new subobject with a number identifying the printout. If
one then comes to an object that is already marked with the printout id, it
is a repeat, and is marked as such, and the search of that branch is
terminated. Then, in a second scan, one can print out the object with the
multiple references of subobjects given increasing number labels preserving
the given natural order of the subobjects.
The double scan is done in part in order to write out the loops with
numbers that comes in a logical order to the reader. With a single scan,
the number printed out would be the one that one gets when first
discovering it is a loop, which is at the second occurrence of the repeated
object. In the example above, one would instead get
[:0, :0, :1]
0: sqrt
as the second "sqrt" is discovered before the second "f", and there is the
additional problem to indicate that the topmost object "f" = :1 is
self-referential. This is logically correct, but backwards to the reader,
as the natural order of outermost-towards-innermost is not respected by the
label numbers.
Hans Aberg
* Email: Hans Aberg <mailto:[EMAIL PROTECTED]>
* Home Page: <http://www.matematik.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>