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

Re: [Scheme-reports] Write procedure is not backwards compatible



On 2012-07-01, at 6:57 PM, Aaron W. Hsu wrote:

> Jonathan Rees <jar@x> wrote:
> 
>> Ouch! If true, I second this comment. Backward compatibility
>> for write is pretty important. Consider the case of running
>> an R5RS (or R7RS) program in an R7RS implementation to generate 
>> a file that will be consumed by an R5RS implementation. 
>> 
>> There is no mention of this incompatibility in the section
>> "Language changes since R5RS".
> 
> Marc Feeley wrote:
> 
>> Formal Comment
>> 
>> Submitter's name: Marc Feeley
>> Submitter's email: feeley at iro.umontreal.ca
>> 
>> Summary: Write procedure is not backwards compatible
>> 
>> R7RS introduces a new output procedure called write-simple, which has
>> the same semantics as the R5RS write procedure.  On the other hand,
>> the R7RS write procedure handles shared structures differently than
>> the R5RS.  For example :
>> 
>>  (let ((x (list 1 2))) (write (list x x)))
>> 
>>      displays ((1 2) (1 2)) in an R5RS system
>>  and displays (#0=(1 2) #0#) in an R7RS system
> 
> People are reading this wrong. The intention here is that WRITE 
> properly handle circular structures that cannot be printed in 
> fully expanded form without infinite output. That is to say, the 
> above interpretation of write is incorrect, IIRC.  We do not 
> guarantee the same shared structure layout of a written structure, 
> but provide a means of serializing circular structures that 
> cannot be serialized with WRITE-SIMPLE.
> 
> This was not added to the R5RS list of incompatibilities because it 
> is not incompatible. Any defined output of R5RS in this case, 
> dealing with normal, non-self referential (circular) structures, 
> should end up the same way; it is circular structures whose contents 
> refer to itself that will be specified now, where they were not, 
> to my understanding, in R5RS.
> 
> If the standard is not clear on this, we should fix this, as this is 
> not an issue of whether we should swap WRITE-SIMPLE with WRITE, but 
> one of clearly indicating what should use the circular structure 
> formatting.

That's not what I understood.

By the way, I'd like to see how this is implemented.  I tried the latest Chibi Scheme, which is meant to be more or less a reference implementation for R7RS, and it gives an infinite loop on:

   (write (let ((x (cons 1 2))) (set-cdr! x x) x))

The semantics you suggest, while it would be compatible with R5RS and would avoid infinite loops, would not provide structure sharing information that datum labels are meant to give (and which are necessary to reconstruct the same graph structure when it is read back).  It would be sad to cripple the implentation like this.

Marc