> From: Mark H Weaver <m...@netris.org> >> It is curious that action of 'copy' really means the >> action of 'create a copy with different properties'. >> >> Shouldn't (string-copy "a") create another immutable string? > > Why would you want to copy an immutable string? > >> Likewise, shouldn't (substring "abc" 1) return an immutable > substring?
I was being too snarky and rhetorical. Gotta stop writing e-mail before getting coffee. To say something possibly semi-constructive... The word 'string' in Scheme is overloaded to mean both string immutables and string mutables. Since a string immutable can't be modified to be a mutable, they really are different object types. String mutables appear to still exist in the latest draft of R7RS. Many of the procedures that operate on strings will are overloaded to take both immutables and mutables, but some, like string-set! take only mutables. There is an obvious syntax to construct a string immutable object: namely to have it appear as a literal in the source code. There thus isn't a need for a constructor function. There is a need for a constructor function to create string mutables, because a literal string in the source code indicates a string immutable. There are such constructors: (string <char> ...) and (make-string k <char>) which is fine. But there is no constructor for a string mutable that initializes it with a string in Guile 2.0. There was in Guile 1.8, where you could do (define <var-name> <string-literal>). So instead, syntactically, we now have to use 'string-copy' or 'substring' for its *side-effects*, namely that it doesn't mark the copy immutable. Those are rather poor and confusing names for constructors. If making such a suggestion weren't pointless, I'd pitch the idea of overloading 'string' or 'make-string' so they can be used as a constructor of a string mutable. Something like (string <string-literal>) or (make-string <string-literal>). This would be clearer than using string-copy, I think. Thanks, Mike