if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?
If strings are vectors, why are they immutable?
489 views Asked by Golo Roden At
2
if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?
Strings are not immutable in Common Lisp, they are mutable:
*
is the last result from the Lisp listenerThe only thing you should not do is modifying literal strings in your code. The consequences are undefined. That's the same issue with other literal data.
For example a file contains:
If we compile the file with
compile-file
, then the compiler might detect that those strings are equal and allocate only one string. It might put them into read-only memory. There are other issues as well.Summary
Strings are mutable.
Don't modify literal strings in your code.