Re: Reference Implementation: trimmed/lazy, wrapped/char and the output state variable Marc Nieper-Wißkirchen (17 Feb 2019 15:25 UTC)

Re: Reference Implementation: trimmed/lazy, wrapped/char and the output state variable Marc Nieper-Wißkirchen 17 Feb 2019 15:25 UTC

Am So., 17. Feb. 2019 um 15:39 Uhr schrieb Alex Shinn <xxxxxx@gmail.com>:
>
> On Sat, Feb 16, 2019 at 7:29 PM Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:
>>
>> In the reference implementation, the state variable "output" is
>> changed locally in the procedures "trimmed/lazy", "wrapped/char",
>> "upcased" and "downcased". The original version of "output" is saved
>> and called by the modified version of "output".
>>
>> This does not yield the correct behavior in all cases as in the
>> following example:
>>
>> (fn ((o output))
>>   (sequence
>>      (with! (output (make-my-output o)))
>>      (wrapped/char (sequence FMT1 (with! (output o)) FMT2)))
>
>
> What do you expect the correct behavior to be?

Thanks for taking a look at this.

In my example, the reference implementation won't wrap the lines
produced by FMT2 because the state variable "output" has been set to a
value it had before executing "wrapped/char".

However, the fact that "wrapped/char" (and some other procedures) make
use of the "output" state variable is an implementation detail and not
part of the specification of SRFI 159. Thus by SRFI 159 as written,
modifying "output" should be transparent to "wrapped/char" et al.

Likewise, the following will lead to unexpected results:

(sequence (wrapped/char (with! (output XXX)) FMT1)) FMT2)

The reference implementation installs the old "output" when FMT2 is
being executed. Just by reading the specification of wrapped/char,
there is no reason to assume that "output" is not XXX when FMT2 is
being executed.

Instead of making the reference implementation compliant, it is
probably a much better idea to add to SRFI 159 as an errata that
non-locally modifying "output" using "with!" can lead to unexpected
results.

Marc