[R6RS] Immutable strings [was: Unicode scalar value escape sequences]

dyb at cs.indiana.edu dyb
Thu Mar 24 14:20:18 EST 2005


I think we should definitely retain mutable strings.  I'd prefer we not
add a mechanism for creating immutable strings, outside of the existing
immutable string constants.  I'm not adamant about this, but it seems
an unnecessary additional complication.  Consider string-append (and
routines like it).  If it returns a mutable string, do we have another
version that returns an immutable string?  Or is mutability a property
derived from its inputs by some contagion rule?  If the latter, do we need
mutable->immutable and immutable-mutable procedures so that we can make
sure string-append gets the inputs we want to guarantee it produces the
output we want?  The same kinds of problems arise if we can dynamically
create both mutable and immutable pairs.

> In my mind, the answer to this question is tied to the removal of
> SET-CAR! and SET-CDR!  Removal of STRING-SET! would certainly break
> lots of existing code.

Yes, in that respect.  But in other respects, the question is quite
different.  Mutable pairs complicate static analysis and complicate or
defeat certain useful optimizations, like deforestation.  Mutable strings
are not nearly as big of a problem.  Immutable pairs have advantages
over mutable pairs in a generational garbage collector that immutable
strings do not have over mutable strings.

I suggest we keep string-set!, that all strings other than constants
(if even constants) be mutable, and that we flush set-car! and set-cdr!,
making all pairs immutable.  Because of the complications mentioned at
the top of this note, if we're not going to make all pairs immutable,
I suggest that all pairs (except possibly constants) be mutable.

Kent


More information about the R6RS mailing list