Re: What should other string-returning procedures do? Per Bothner 23 Dec 2014 18:05 UTC

On 12/20/2014 08:21 AM, John Cowan wrote:
> I think this is an excellent SRFI, and I support it.
> However, it specifies only that `make-string` must return
> a variable-length string.  What about `string`, `string-*case`,
> `substring`, `string-copy`, and `string-map`?

Well, it does say:

    Standard Scheme functions that return mutable strings, such as make-string or
    string-copy, are specified to return variable-size mutable strings by default.

> My notion is that `string` ought to be free to return either a
> variable-length or a fixed-length string, and that the others ought
> to be guaranteed to return variable-length strings if (not iff) their
> string argument is variable-length.

We could do something like that, but is the extra implementation flexibility
justified by the extra complexity?  There is something to be said for just
having two kinds of strings: immutable and mutable variable-sized.  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,
and some may return fixed-size mutable strings.

In retrospect, it would have been cleaner if functions such as string-upcase
or string-append were defined to return immutable strings, but for compatibility they
must returns mutable strings, though not necessarily variable-sized ones.

> Also, what about conversions between fixed-length and variable-length
> strings?  On Kawa, these would be no-ops, but on other systems they
> might not be.

If we specify that some functions (for example string-copy) always returns
a variable-size string, then we don't need explicit conversion functions:
string-copy will do.

If we split up the r7rs string functions, I suggest:

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

(These are functions it would be plausible for a future RnRS to specify that they
should return an immutable string.)

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