Mark H Weaver <m...@netris.org> writes: > Empty string literals ("") in the program text are still immutable, so > (string-upcase! "") still throws an error. > > I admit that this is an arguable point. Section 3.4 (Storage model) of > the R5RS (and the R7RS draft) says "It is an error to attempt to store a > new value into a location that is denoted by an immutable object." An > empty string denotes no locations, so perhaps this should not be an > error after all. > > The right place to fix this would probably be in > `scm_i_string_start_writing' (strings.c). > > What do other people think?
Mutating list operations are allowed on '() (and do not change it). '(), the empty list structure, is eq? to itself regardless how you arrived at it. I think it would give some logical symmetry if the same held for "" and #(). "" is obviously a valid substring of either mutable or immutable strings. The result of (string-append! x "") should leave the immutability state of x alone. One rationale behind that is more or less that the immutability is a property of the characters of the string, and "" has no characters of its own and does not contribute to the characters. If there are predicates "immutable-string?" and "mutable-string?" (I don't have Guilev2 installed), then "" would be the only string satisfying both predicates. Efficiency of implementation might make other choices preferable, but that's what I would consider logically satisfying. -- David Kastrup