views:

40

answers:

2
+2  A: 

Reverse creates and returns a new list. Rotatef (just as setf, incf and the like) modify a place. You will have to copy-list or copy-tree your element to create a new list that you then modify.

Svante
Thanks a lot! I have never heard of those list functions. I was previously trying to "copy" the list using append, initializing temp as an empty list and appending get-element but it didn't work, temp remained empty.
Xap
+3  A: 

Some other remarks:

  • instead of a getter and setter method, use an accessor method. That's usually preferred.

  • lists are created with functions like LIST or COPY-LIST. A list written as '(1 b 2) is in source code a literal constant and should not be changed. It is undefined in the CL standard what happens if you try to change a literal list. This can have unwanted effects. If you have a literal list and you want to modify it, you should first copy it with COPY-LIST (or COPY-TREE) and modify that copy.

  • you also need to learn the difference between non-destructive operations like REVERSE and possibly destructive operations like NREVERSE. If you want the original list to be unchanged, use non-destructive operations. The nature of the list or sequence operations is described in the Common Lisp Hyperspec for each operation.

Rainer Joswig