Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!hookup!swrinde!pipex!uunet!sytex!smcl
From: smcl@sytex.com (Scott McLoughlin)
Subject: Re: why no substring sharing?
Message-ID: <02aJwc1w165w@sytex.com>
Sender: bbs@sytex.com
Organization: Sytex Access Ltd.
References: <ROCKWELL.94Nov28162254@nova.umd.edu>
Date: Tue, 29 Nov 1994 04:16:32 GMT
Lines: 48

rockwell@nova.umd.edu (Raul Deluth Miller) writes:

> Tom Lord:
> :  (UNSHARE-SUBSTRING! <string>) => <unspecified>
> :	   Modify the argument to no longer share state with
> :	   any other string in the system.
> 
> This seems somewhat ambiguous.  (e.g. is it a variable that is being
> modified?  a location?  What does it mean for this argument to be not
> shared?)
> 
> If such a thing were implemented, presumably it would be not be
> designed as a mutator but as a pure function.
> 
> -- 
> Raul D. Miller          N=:((*/pq)&|)@                 NB. public e, y, n=:*/
> <rockwell@nova.umd.edu> P=:*N/@:#               NB. */-.,e e.&factors t=:*/<:
>                         1=t|e*d    NB. (,-:<:)pq is four large primes, e medi
> x-:d P,:y=:e P,:x                  NB. (d P,:y)-:D P*:N^:(i.#D)y [. D=:|.@#.d

Howdy,
        You know, I was thinking the same thing. I started to make
a post and then got to thinking.
        A shared substring would presumably be implemented as a 
reference to a simple string (or whatever char array representation
one wishes to use) and start/end indexes into the representation.
The UNSHARE-SUBSTRING! primitive need not make a simple-string at
all. It would only need to make sure that the representation 
component was not referenced by any other live object, i.e. copy
the underlying representation and alter the start/end indexes
accordingly.
        This makes me wonder what the SHARED-SUBSTRING? or whatever
predicate would now return on the altered object. Is this a predicate
about the representation method used for the string (Simple-String
vs. a displaced representation) or a predicate that tells us
whether the string is indeed shared or not. The latter would require
cooperation from the GC/reference counts/etc which sounds expensive.
        Indeed, a function that returned a simple string representation
and left the object alone might be simpler. Perhaps the proposed 
design was influenced by SCM's string representation, which if I 
remember correctly, uses a separate header that contains a type tag
length field and pointer to a char array stored in a heap managed
by malloc/free.

=============================================
Scott McLoughlin
Conscious Computing
=============================================
