[plt-scheme] mutable strings

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Aug 21 18:38:21 EDT 2006

At Mon, 21 Aug 2006 18:33:47 -0400, Matthias Felleisen wrote:
> 
> On Aug 21, 2006, at 6:16 PM, Paul Graham wrote:
> 
> > We're trying to undo Scheme's fussiness about immutable strings.
> > More precisely, we're writing another language that macroexpands
> > into Scheme code, and in this language you can modify strings.
> >
> > Is it possible to have a mutable string within a mzscheme function?
> >
> > 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?
> 
> Do you mean something like this?
> 
>  > (define foo (list->string (string->list "hello world")))
>  > (string-set! foo 3 #\x)
>  > foo
> "helxo world"

I think he's probably referring to the fact that read produces
immutable strings:

  > (immutable? (read (open-input-string "\"abc\"")))
  #t

but yes, if you create a string nearly any way except read or
string->immutable-string, you get a mutable string.

Robby



Posted on the users mailing list.