Subject: Re: Simple newbie list processing troubble
From: Erik Naggum <>
Date: 30 Sep 2002 18:50:57 +0000
Newsgroups: comp.lang.lisp
Message-ID: <>

* Peder Y
| (defun foo (lst)
|   (loop for x in lst do
|               (setf (car x) 'A)))

* Marco Antoniotti
| The above will not necessarily work because you are changing the list as you
| are traversing it.  This is specifically mentioned in the language standard.

  Huh?  The only way the above code would work is by changing the car of each
  cons cell that is the car of the cons cells that are traversed.  This is not
  even close to the restriction of modifying the list structure itself, which
  also means the cdr.  But even (cdr x) would be just fine, because it would
  only modify the conses that were the elements of the list.

  In particular, after (foo bar), bar would have a contents like
  ((A ...) (A ...) (A ...) ...).

Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.