[plt-scheme] mutable strings

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Mon Aug 21 18:37:55 EDT 2006

On 21 Aug 2006 22:16:59 -0000, Paul Graham <pg at ycombinator.com> wrote:
> Because I'd considered, for example, hacking the reader so that
> a double-quoted string was copied on being read in, and the copy,
> which was therefore mutable, was used in the code.  But can you
> even have a mutable string within code?

You can put mutable objects (including strings) in syntax objects, but
I don't think this will give you the behavior you want.  I don't
believe the same object will be returned to the code when it is run.
You can, however, define a language with a new #%datum transformer
that produces mutable strings.  The naive approach will produce a new
mutable copy of the literal string at each evaluation; with a little
more work I think you could fix it to construct a single mutable
string once and return a reference to it at each evalutation.  It
depends which behavior you prefer.

-- 
Carl Eastlund


Posted on the users mailing list.