setf not working

Willem Broekema metawilm at gmail.com
Thu Oct 3 07:50:56 UTC 2013


On Thu, Oct 3, 2013 at 9:44 AM, Elias Mårtenson <lokedhs at gmail.com> wrote:

> On 3 October 2013 15:40, Willem Broekema <metawilm at gmail.com> wrote:
>
> > I guess you are modifying the value of *var*, which is not allowed if it
> is
> > a quoted list. That's why you need e.g. (list .. ..) or (copy-tree '(..
> ..))
> > instead of '(.. ..).
> >
> http://stackoverflow.com/questions/10365470/modifying-a-list-passed-as-a-parameter-gives-different-results-in-sbcl-and-clisp
>
> (SETQ *var* ...) does not change the list. It merely reassigns the
> variable.
>

The value that is assigned, that is the problem. That is probably a
modified literal list.

If there is literally this in the code: (setq *var* '(. . .))
then the compiler is free to extract that '(. . .) part and reuse it all
the time this setq form is executed. It can create one literal object and
keep it in memory, and always uses it as value. It does not need to build a
new list every time.
If you modify that special object, e.g. by setting the car of it, then
compiler may ignore that and upon the next setq set the value with modified
car.

- Willem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20131003/b8c99a83/attachment.html>


More information about the pro mailing list