i defined a special variable *unsorted-lst* and a function for reseting this variable in my script:
(defparameter *unsorted-lst* nil)
(defun reset-to-unsorted-list ()
(setf *unsorted-lst* '(1 3 0 22 3 1 3 299 31 5 0 3 7 96 24 44))
(format t "after reset: ~a~%" *unsorted-lst*)
)
After that i copy them to SBCL console for testing, i did:
* (setf *unsorted-lst* '(1 2 3))
(1 2 3)
* (reset-to-unsorted-list)
after reset: (1 3 0 22 3 1 3 299 31 5 0 3 7 96 24 44)
NIL
Everything works fine so far. Then i did
* (setf (second *unsorted-lst*) 100)
100
* (reset-to-unsorted-list)
after reset: (1 100 0 22 3 1 3 299 31 5 0 3 7 96 24 44)
NIL
The setf in function seems did not work, the second element value still was 100. It really confuse me. I had to type setf command directly in console to make the change:
* (setf *unsorted-lst* '(1 3 0 22 3 1 3 299 31 5 0 3 7 96 24 44))
(1 3 0 22 3 1 3 299 31 5 0 3 7 96 24 44)
* *unsorted-lst*
(1 3 0 22 3 1 3 299 31 5 0 3 7 96 24 44)
Now it works. I cannot tell what wrong it is? Are there some misunderstanding of setf? or variable?
reset-to-unsorted
as a static variable. When you assign its value to variable and make a change to the underlying object through that variable, you're changing the one value that exists. – Ellamaeellan