lisp - If strings are vectors, why are they immutable? -
if strings vectors of characters, , vector's elements can accessed using elt, , elt setf-able - why strings immutable?
strings not immutable in common lisp, mutable:
*
last result lisp listener
cl-user 5 > (make-string 10 :initial-element #\-) "----------" cl-user 6 > (setf (aref * 5) #\|) #\| cl-user 7 > ** "-----|----" cl-user 8 > (concatenate 'string "aa" '(#\b #\b)) "aabb" cl-user 9 > (setf (aref * 2) #\|) #\| cl-user 10 > ** "aa|b"
the thing should not modifying literal strings in code. consequences undefined. that's same issue other literal data.
for example file contains:
(defparameter *lisp-prompt* "> ") (defparameter *logo-prompt* "> ")
if compile file compile-file
, compiler might detect strings equal , allocate 1 string. might put them read-only memory. there other issues well.
summary
strings mutable.
don't modify literal strings in code.
Comments
Post a Comment