> (setq x '(1 2 3) y '(4 5 6)) (4 5 6) > (setq z (append x y)) (1 2 3 4 5 6) > x (1 2 3) > y (4 5 6) > z (1 2 3 4 5 6) > (setq w (nconc x y)) (1 2 3 4 5 6) > x (1 2 3 4 5 6) > y (4 5 6) > w (1 2 3 4 5 6) >以下のnconcとappendの定義の違いを見て理解してください.
(defun nconc* (a &rest args) (cond ((null args) a) (t (apply #'nconc* (cons (nconc2 a (car args)) (cdr args)))))) (defun nconc2 (a b) (rplacd (last a) b) a) (defun last (x) (if (null (cdr x)) x (last (cdr x)))) (defun append* (&rest args) (cond ((null args) nil) (t (apply #'append2 (car args) (apply #'append (cdr args)))))) (defun append2 (a b) (if (null a) b (cons (car a) (append2 (cdr a) b))))