It is usually said that (pop stack) is equivalent of (prog1 (first stack) (setf stack (rest stack))) or (let ((elt (first stack))) (setf stack (rest stack)) elt). I don't understand why the following function doesn't work as an equivalent of built-in pop:

- Code: Select all
`(defun my-pop (lst)`

(let ((x (first lst)))

(setf lst (rest lst))

x))

Example:

- Code: Select all
`? (setf lstA '(a b c))`

? (my-pop lstB)

A

? lstA

(A B C)

? (setf lstB '(a b c))

? (pop lstB)

A

? lstB

(B C)

But:

? (setf lstC '(a b c))

? (let ((x (car lstC)))

(setf lstC (cdr lstC))

x)

A

? lstC

(B C)