Re: SRFI 130 - "span" prefix Per Bothner 05 Dec 2015 17:19 UTC


On 12/05/2015 08:51 AM, John Cowan wrote:
> Shiro Kawai scripsit:
>
>> Gauche's GC doesn't move objects, but for copying GCs, one way is to keep
>> the pointer to the head of the original string and the offset.
>
> Sorry, I wasn't clear.  Consider this:
>
> gosh> (define foo (make-string 1000000 #\z))
> foo
> gosh> (define bar (substring foo 1 999998)) ; presumably shares with foo
> bar
> gosh> (begin (string-set! foo 500000 #\Z) 42) ; suppresses lengthy output of string-set!
> 42
> gosh> (string-ref bar 499999)
> #\z
>
> Now when the string-set! was executed, the sharing between foo and bar
> strings had to be broken somehow, because we see that mutating foo did
> not affect bar.  How does that work?

The easiest way seems to be a copy-on-write flag.  If substring returns
a mutable string, you need the flag on both foo and bar.

This is what I'm doing in the new (in-progress) Kawa re-implementation
of strings and arrays.
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/