Contents    Page-10    Prev    Next    Page+10    Index   


nconc concatenates two lists to form a single list; instead of copying the first list as append does, nconc modifies the end of the first list to point to the second list.

(nconc (list 'a 'b 'c) '(d e))   ->  (a b c d e)

public static Cons nconc (Cons x, Cons y) {
  Cons ptr = x;
  if (x == null)
     return y;
   else { while (rest(x) != null)
            x = rest(x);     // walk to end
          setrest(x, y);
          return ptr; } }

(defun nconc (x y)
  (let (ptr)
    (setq ptr x)
    (if (null x)
        (progn           ; progn is like {  }
          (while (not (null (rest x)))
             (setq x (rest x)) )
          (setf (rest x) y)
          ptr) ) ))