Mike Gran <spk...@yahoo.com> writes: > 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? As I understand it, in the Scheme standards (at least before R6RS's immutable pairs) the rationale behind marking literal constants as immutable is solely to avoid needlessly making copies of those literals, while flagging accidental attempts to modify them, since that is almost certainly a mistake. If that is the only rationale for marking things read-only, then there's no reason to mark copies read-only. The philosophy of Scheme (at least before R6RS) was clearly to make almost all data structures mutable. Following that philosophy, in Guile, even though (substring "abc" 1) postpones copying the string buffer, it must create a new heap object. Once you've done that, it is feasible to implement copy-on-write. Now, the immutable pairs of R6RS and Racket have an entirely different rationale, namely that they enable vastly more effective optimization in a compiler. In this case, presumably you'd want copies to retain the immutability. Mark