[iterate-devel] fishy iterate use of delete...

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Wed Nov 2 16:47:40 UTC 2005


Faré wrote:
>Indeed, (delete ...) has side-effects and doesn't preserve its second
>argument.

Although I can hardly imagine any implementation where DELETE on lists would operate in ways that break the code (except for an ANSI-compliance stress tester mode), it's not correct use of DELETE by the CLHS.

 Thus, a minimally disruptive patch would be to replace
>(delete entry index) with (setf index (delete entry index)) twice,
Funny. It seems the code has an extra element in the list precisely to avoid the well-known "delete yields empty list not reflected in variable" Lisp FAQ issue, but CLHS precisely disables such optimization when using DELETE (instead of a self-written naive implementation).

>Someone who understands the code
>better audit what is being done by the considered functions.

> and (delete nil temps) with (remove nil temps).
Assuming you're talking about make-mv-dsetqs:
    (let ((mv-setq `(multiple-value-setq ,vars ,value))
	  (temp-vars (delete nil temps)))
Great, that's not just being picky about standard compliance, you discovered a real bug in the code! temps is still used afterwards and DELETE destroys it. REMOVE MUST be used instead.

Here's a testcase I came up with:
(let (x y z) (dsetq (values nil x (y z)) (values 1 'a '(b c))) (list x y z))
must yield (a b c), not (a nil nil).

Regards,
	Jörg Höhle.



More information about the iterate-devel mailing list