Function: copy-alist

copy-alist is a function defined in fns.c.

Signature

(copy-alist ALIST)

Documentation

Return a copy of ALIST.

This is an alist which represents the same mapping from objects to objects, but does not share the alist structure with ALIST. The objects mapped (cars and cdrs of elements of the alist) are shared, however. Elements of ALIST that are not conses are also shared.

Other relevant functions are documented in the list and alist groups.

Probably introduced at or before Emacs version 17.

Shortdoc

;; alist
(let* ((old '((foo . bar))) (new (copy-alist old))) (eq old new))
    => nil
;; list
(copy-alist '((1 . a) (2 . b)))
    => ((1 . a) (2 . b))

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
  if (NILP (alist))
    return alist;
  alist = concat (1, &alist, Lisp_Cons, false);
  for (Lisp_Object tem = alist; !NILP (tem); tem = XCDR (tem))
    {
      Lisp_Object car = XCAR (tem);
      if (CONSP (car))
	XSETCAR (tem, Fcons (XCAR (car), XCDR (car)));
    }
  return alist;
}