I'm getting some strange behavior when I try to set a global parameter within a method.
(defparameter *global-var-1* nil)
(defun method1 ()
(setf *global-var-1* '())
(format t "~a~%" *global-var-1*)
...
(loop
...
(setf *global-var-1* '(a))
(format t "~a~%" *global-var-1*)
(nconc *global-var-1* (list '(b c))))
In the above code, when I call method1, the first format statement always prints nil
as expected. The second format statement prints (A)
the first time method1 is called, but the second time it prints (A (B C))
. The third time (A (B C) (B C))
and so on. Instead of setting *global-var-1*
to (A)
, setf seems to be setting it to the previous known value. What am I doing wrong? BTW, I was setting *global-var-1
to (A)
because nconc
won't work with an empty list. I remove (A)
later on before exiting method1.