Function: delq

delq is a function defined in fns.c.

Signature

(delq ELT LIST)

Documentation

Delete members of LIST which are eq to ELT, and return the result.

More precisely, this function skips any members eq to ELT at the front of LIST, then removes members eq to ELT from the remaining sublist by modifying its list structure, then returns the resulting list.

Write (setq foo (delq element foo)) to be sure of correctly changing the value of a list foo. See also remq, which does not modify the argument.

Other relevant functions are documented in the list group.

Probably introduced at or before Emacs version 19.29.

Shortdoc

;; list
(delq 2 (list 1 2 3 4))
    => (1 3 4)
  (delq "a" (list "a" "b" "c" "d"))
    => ("a" "b" "c" "d")

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
  Lisp_Object prev = Qnil, tail = list;

  FOR_EACH_TAIL (tail)
    {
      Lisp_Object tem = XCAR (tail);
      if (EQ (elt, tem))
	{
	  if (NILP (prev))
	    list = XCDR (tail);
	  else
	    Fsetcdr (prev, XCDR (tail));
	}
      else
	prev = tail;
    }
  CHECK_LIST_END (tail, list);
  return list;
}