Next: , Previous: , Up: srfi shared structures   [Index]


2.14.3 Rationale

R5RS scheme and IEEE scheme provide the procedure write, which prints machine–readable representations of lists and other objects. However, the printed representation does not preserve information about what parts of the structure are shared, and in the case of self–referential objects the behavior of write itself is undefined; it is permitted to go into an infinite loop or invoke the dreaded curse of the nasal demons.

For example, it is possible to have a list within which two or more members are the same string (in the sense of eq?), but when the list is written, there is not sufficient information in the representation to recover the eq? relationship. When the list is read back in, there will be two or more copies of the string which are eqv? but not eq?.

As an example of the second problem, the results of evaluating:

(begin (define a (cons 'val1 'val2))
       (set-cdr! a a)
       (write a))

are undefined; in R5RS parlance, calling write on such a structure “is an error”, but not one that is necessarily signalled. The routine is permitted to print a nonstandard notation such as the one proposed in this standard or a different one, fail silently, signal an error, go into an infinite loop, or make demons fly out of your nose. Some of these results are unacceptable in some cases. This SRFI hopes to provide a standard way of dealing with this problem by providing a method of writing data which is guaranteed to be well–behaved and predictable even on data containing shared structures.

The extended functionality described below in the implementation of write-with-shared-structure is already present in the write function of several major scheme implementations (PLT, SISC, Chez, Bigloo, MIT scheme, and possibly others).


Next: , Previous: , Up: srfi shared structures   [Index]