Solution
First of all, what you are seeing is an error
, not a warning
.
Second, you cannot turn it off, but you can avoid it by copying the immutable string:
(print (do ((str (copy-seq "foobar"))
(i 0 (+ i 1)))
((= i (length str)) str)
(setf (char str i) #\!)))
Motivation
Why some data is made immutable is a topic much discussed on the web.
The basic reasons are:
- safety in a multithreaded environment and
- better compilers
Justification
As per the manual:
An attempt to modify read-only data SIGNALs an ERROR. Program text and quoted constants loaded from files are considered read-only data. This check is only performed for strings, not for conses, other kinds of arrays, and user-defined data types.
This is explicitly permitted by the ANSI CL spec:
implementations are not required to detect attempts to modify immutable objects or cells; the consequences of attempting to make such modification are undefined