Re: What should other string-returning procedures do? John Cowan 24 Dec 2014 01:33 UTC

Per Bothner scripsit:

> If we allow some functions to return fixed-size mutable strings, I
> think it would be simpler to just specify some functions always return
> variable-sized strings,

My concern is that in some implementations, variable-length mutable
strings may be much less efficient to access than fixed-length strings,
while being easier to vary.  For example, suppose variable-length
strings were implemented as ropes.  That makes string-append! and
string-replace! very fast (no copying), but requires more work from
string-ref, string-map, and so on.

> Procedures that may return a fixed-size string:
>
>   string string-upcase string-downcase string-foldcase substring
>   string-append list->string

+1

> Procedures that must return a variable-size string:
>
>   make-string string-copy

I agree for make-string.  However, I suggest splitting string-copy into
three functions:

string-copy returns a fixed-length mutable string (that is, it is an
error to vary its length)

string-variable-copy returns a variable-length mutable string

string-immutable-copy returns an immutable string (that is, it is an
error to mutate it)

These three can be implemented on systems with three, two, or one kind
of strings, as "it is an error" does not require that the error be
detectable.

--
John Cowan          http://www.ccil.org/~cowan        xxxxxx@ccil.org
Verbogeny is one of the pleasurettes of a creatific thinkerizer.
        --Peter da Silva