[Ecls-list] ECL and destructive operations: problem?

Rui Maciel rui.maciel at gmail.com
Fri Nov 13 21:08:15 UTC 2009


While following Practical Common Lisp's section on list processing[1] I've 
stumbled on what appears to be a problem. On the section regarding destructive 
and non-destructive operations an example is given to show the effects that 
destructive operations have on shared structures. Yet, when running that 
example on ECL the outcome isn't the same as the one presented in the book. 
So, while the book's example goes as:

<code>
(defparameter *list-1* (list 1 2))
(defparameter *list-2* (list 3 4))
(defparameter *list-3* (append *list-1* *list-2*))
*list-1*                  ==> (1 2)
*list-2*                  ==> (3 4)
*list-3*                  ==> (1 2 3 4)
(setf (first *list-2*) 0) ==> 0
*list-2*                  ==> (0 4)     ; as expected
*list-3*                  ==> (1 2 0 4) ; maybe not what you wanted
</code>


ECL's outcome is:
(defparameter *list-1* (list 1 2))
(defparameter *list-2* (list 3 4))
(defparameter *list-3* (append *list-1* *list-2*))
*list-1*                  ==> (1 2)
*list-2*                  ==> (3 4)
*list-3*                  ==> (1 2 3 4)
(setf (first *list-2*) 0) ==> 0
*list-2*                  ==> (0 4)     ; as expected
*list-3*                  ==> (1 2 3 4) ; woops!
</code>


When I test the same example on CLISP the outcome is exactly the same as the 
book's outcome.

So, is this a problem or am I missing something?


Rui Maciel
[1] http://gigamonkeys.com/book/they-called-it-lisp-for-a-reason-list-
processing.html




More information about the ecl-devel mailing list