Function: rng-substq

rng-substq is a byte-compiled function defined in rng-util.el.gz.

Signature

(rng-substq NEW OLD LIST)

Documentation

Replace first member of LIST (if any) that is eq to OLD by NEW.

LIST is not modified.

Source Code

;; Defined in /usr/src/emacs/lisp/nxml/rng-util.el.gz
(defun rng-substq (new old list)
  "Replace first member of LIST (if any) that is `eq' to OLD by NEW.
LIST is not modified."
  (cond ((null list) nil)
	((eq (car list) old)
	 (cons new (cdr list)))
	(t
	 (let ((tail (cons (car list)
			   nil))
	       (rest (cdr list)))
	   (setq list tail)
	   (while rest
	     (let ((item (car rest)))
	       (setq rest (cdr rest))
	       (cond ((eq item old)
		      (setcdr tail
			      (cons new rest))
		      (setq rest nil))
		     (t
		      (setq tail
			    (setcdr tail
				    (cons item nil))))))))
	 list)))