Looking at the release notes of SBCL 2.2.7, i see an interesting new 'minor incompatible change':
minor incompatible change: literal objects (strings, in particular) in compiled code may at the discretion of the runtime be placed in read-only memory. Violations of CLHS 3.7.1 could produce memory faults. If ":PURIFY NIL" is given to SAVE-LISP-AND-DIE then no read-only memory will be used.
CLHS section on the literal objects says the following operations are considered destructive:
array: Storing a new value into some element of the array, or performing a destructive operation on an object that is already such an element. Changing the fill pointer, dimensions, or displacement of the array (regardless of whether the array is actually adjustable). Performing a destructive operation on another array that is displaced to the array or that otherwise shares its contents with the array.
So, as far as i understand, doing something like
(defun inc-char-at (idx s)
(setf (char s idx)
(code-char (1+ (char-code (char s idx)))))
s)
(inc-char-at 2 "aaaaa")
can't be considered to be safe.
Does this mean, that the rule of thumb is not to use string literals at all, except in situations where there are semantically immutable (like format strings or constants), preferring make-array of characters instead?
How can it be considered to be the 'minor incompatibility' then?
And, what is more important, does the standard clarify which cases would make a literal (not necessarily a string) to be considered immutable and therefore put into read-only memory?