I'm noticing some inconsistency in the output of this code in Clisp
:
(defvar str "Another")
(setf (char str 3) #\!)
When I run it from the repl, I get the desired result:
[1]> (defvar str "Another")
STR
[2]> (setf (char str 3) #\!)
#\!
[3]> str
"Ano!her"
[4]>
However, when I run it from a script, I get a warning about modifying a readonly string:
*** - Attempt to modify a read-only string: "Another"
I got that error when running this code:
(print (do ((str "foobar")
(i 0 (+ i 1)))
((= i (length str)) str)
(setf (char str i) #\!)))
What's the point of making the string read-only
(I'm assuming this is the same as immutable
) when the binding will dissappear when the block ends?
And, why the discrepancy between the two outputs?
Lastly, is there a way to turn it off? I don't find the warning particularly useful.