[plt-scheme] efficient string operations yielding immutable strings

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Thu Mar 25 23:40:29 EST 2004

Motivation: Now that I've started coding with immutable strings, mutable
strings are seeming more and more like a special case, and rarely what I
want.  I've written some convenience procedures like
"substring-immutable" and "string-append-immutable" that apply
"string->immutable-string" to the result of the familiar standard
procedures.  From looking at the MzScheme C code, it seems these
convenience procedures of mine are grossly inefficient compared to how
they would be implemented as primitives (they, e.g., cause 2 or 3 string
allocations, when only 0 or 1 is necessary).

Question: If I were to implement a set of string operation primitives
that always yield immutable strings, can someone suggest a visually
lightweight naming convention?  "substring-immutable",
"string-append-immutable", "string-lowercase-immutable", etc. seem
bulky.  I don't really want to use a non-alphanumeric character as a
suffix for this.

P.S.: If there were a mutating operation that turned a mutable string
      immutable, that might be helpful in some cases, but I imagine
      it would overconstrain the Scheme implementation's internals.

-- 
                                             http://www.neilvandyke.org/


Posted on the users mailing list.