I have a function:
(defun multi-push (L P)
(print (if L "T" "F"))
(print P)
(when L
(multi-push (cdr L) (push (car L) P)))
P)
which I have made in an to attempt to push a list onto another list (I am aware the input list L
is reversed. This is by design). The print statements make sense, but when I look at the variable P
, it is not mutated as I expect.
Sample REPL output:
CL-USER> bob
(3 3 3)
CL-USER> (multi-push (list 1 2) bob)
"T"
(3 3 3)
"T"
(1 3 3 3)
"F"
(2 1 3 3 3)
(1 3 3 3)
CL-USER> bob
(3 3 3)
What have I done wrong? I thought PUSH
(according to [http://clhs.lisp.se/Body/m_push.htm]) mutates its second argument in place. I have also tried variations where I POP
L
and PUSH
it onto P
before calling multi-push
on L
and P
again.
one thing of note is that the line (1 3 3 3)
is the output of the function of multi-push
. This also confuses me.