Mike Gran <spk...@yahoo.com> writes: > 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.
Huh? There are _lots_ of strings which are better computed than spelled out. > But there is no constructor for a string mutable that initializes > it with a string in Guile 2.0. (string-copy "xxxxx") > There was in Guile 1.8, where > you could do (define <var-name> <string-literal>). No, it wasn't. guile> (define (x) "xxxxx") guile> (x) "xxxxx" guile> (string-upcase! (x)) "XXXXX" guile> (x) "XXXXX" guile> As you can see, reevaluating the definition suddenly delivers a changed result, because we are not talking about modifying a mutable string initialized with a literal, but about modifying the literal itself. Whether or not you replace the function body with (define y "xxxxx") y instead of just "xxxxx" does not change the result and does not change what happens. y does not refer to a string initialized from the literal, it refers to the literal. And changing the literal is a really bad idea. Just because you do not understand what the code did previously does not mean that the behavior was well-defined. -- David Kastrup