Function: nconc

nconc is a function defined in fns.c.

Signature

(nconc &rest LISTS)

Documentation

Concatenate any number of lists by altering them.

Only the last argument is not altered, and need not be a list.

Other relevant functions are documented in the list group.

View in manual

Probably introduced at or before Emacs version 22.1.

Shortdoc

;; list
(nconc (list 1) (list 2 3 4))
    => (1 2 3 4)

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
  Lisp_Object val = Qnil;

  for (ptrdiff_t argnum = 0; argnum < nargs; argnum++)
    {
      Lisp_Object tem = args[argnum];
      if (NILP (tem)) continue;

      if (NILP (val))
	val = tem;

      if (argnum + 1 == nargs) break;

      CHECK_CONS (tem);

      Lisp_Object tail UNINIT;
      FOR_EACH_TAIL (tem)
	tail = tem;

      tem = args[argnum + 1];
      Fsetcdr (tail, tem);
      if (NILP (tem))
	args[argnum + 1] = tail;
    }

  return val;
}