要改变 plist,只需使用setf
:
(setf (getf *star* :points) 59)
要进行非可变更新,在原始值不受干扰的情况下,您可以执行以下操作:
(defun update-plist (plist indicator new-value)
(let ((other-properties nil))
(loop while plist
for property = (pop plist)
for value = (pop plist)
when (eq property indicator)
do (return-from update-plist (list* property new-value
(append other-properties plist)))
else do (push value other-properties)
(push property other-properties))
(list* indicator new-value other-properties)))
它与您的示例不同:
*star* ;; (:points 6 :color :green)
(update-plist *star* :points 5) ;; (:points 5 :color :green)
*star* ;; (:points 6 :color :green) -- Doesn't change.