[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Scheme-reports] Write procedure is not backwards compatible
On Mon, Jul 2, 2012 at 10:14 PM, Marc Feeley <feeley@x> wrote:
>
> 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))
To get R7RS in Chibi you need to write an R7RS
program, e.g. beginning with
(import (scheme base))
although write was moved so you need to
(import (scheme write))
as well for this example. As a shortcut you
can run "chibi-scheme -xscheme.base", or
you can use the extended repl:
(import (chibi repl))
(repl)
@import-only (scheme base)
which allows ^C interrupts in case you do write
an infinite loop (note you want latest dev to use
(chibi repl)). (chibi repl) uses the R7RS write by
default so you don't actually need to import anything
else.
This is documented more thoroughly in the manual.
--
Alex