// Destructive actions on cons cells and lists: >(setq l '(a b c)) (A B C) >(RPLACA l 'D) (D B C) >l (D B C) >(RPLACD l '(Z)) (D Z) >(RPLACD l 'Z) (D . Z) >(RPLACD l '(Z)) (D Z) >l (D Z) // NCONC is a destructive version of APPEND: >(help 'nconc) ----------------------------------------------------------------------------- NCONC [Function] (not found "gcl.info") From ((NCONC . Lists) gcl-si.info): -- Function: NCONC (&rest lists) Package:LISP Concatenates LISTs by destructively modifying them. ----------------------------------------------------------------------------- >(setq l1 '(a b c)) (A B C) >(setq l2 '(d e f)) (D E F) >(nconc l1 l2) (A B C D E F) >l1 (A B C D E F) >l2 (D E F) >l1 (A B C D E F) >l2 (D E F) >(RPLACA l2 'z) (Z E F) >l2 (Z E F) >l1 (A B C Z E F) ;;;----------------------------------------------------------------------------- ;;; Equality has four tests in LISP: EQ, EQL, EQUAL, and EQUALP ;;; ;;; Read about these in https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node74.html ;;; and try various examples out in your LISP. Here are a few. // EQ tests equality of pointers, EQL of pointers and numbers, EQUAL is // recursive comparison by content: >(eq 1 1) // this is NOT guaranteed. There may be two copies of the integer value 1. T >(eq "foo" "foo") // this is as expected: strings likely get their own copy every time when read. NIL >(eq 'x 'x) // this is guaranteed T >(setq a 'x) X >(setq b 'x) X >(eq a b) // this is guaranteed. Symbols resolve to their bindings, both a & b are bound to the same symbol x T >(eq 10000000 10000000 ) T >(eql 10000000 10000000 ) T >(eql "foo" "foo" ) // EQL is guaranteed to compare values only for numbers, not strings NIL >(equal "foo" "foo" ) // this is guaranteed T >(eq '(a b c) '(a b c)) // this is as expected: the arguments are two different lists with their own separate cons cells NIL >(eq (car '(a b c)) (car '(a b c))) // this is guaranteed T >(equal '(a b c) '(a b c)) // this is guaranteed T >l1 (A B C Z E F) // the result is well-defined, but drives PRINT (the P in REPL) into endless loop: >(nconc l1 l1) (A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C Z E F A B C