Can somebody please explain why 1) & 2) do not destructively alter the input
list and 3) does?
Thanks alot!!!!
1)
> (defun mypush (e l)
(cond ((null l) (cons e ()))
(t (setf l (cons (car l) (mypush e (cdr l)))))))
mypush
> (setq li '(a b c))
(a b c)
> (mypush 'd li)
(a b c d)
> li
(a b c)
2)
> (defun mypush (e l)
(cond ((null l) (cons e ()))
(t (setq l (cons (car l) (mypush e (cdr l)))))))
mypush
> (mypush 'd li)
(a b c d)
> li
(a b c)
3)
> (defun mypush (e l)
(cond ((null (cdr l)) (rplacd l (cons e ())))
(t (setq l (cons (car l) (mypush e (cdr l)))))))
mypush
> (mypush 'd li)
(a b c d)
> li
(a b c d)
>