Subject: Values list (etc.) modified destructively
From: Dieter Kaiser
Date: Tue, 16 Feb 2010 23:31:02 +0100
We have the bug report ID: 712468 "Values list (etc.) modified
destructively".
One simple method might be to support a function which passes a copy of
the global list to the user. E.g.
(defun $values() (copy-list $values))
With such a function we will get
(%i1) a:10;b:20;c:20;
(%o1) 10
(%o2) 20
(%o3) 20
(%i4) x:values(); /* Store a copy in x */
(%o4) [a,b,c]
(%i5) values; /* This is not a copy */
(%o5) [a,b,c,x]
(%i6) values(); /* Output of a copy */
(%o6) [a,b,c,x]
(%i7) kill(a); /* We kill the first entry */
(%o7) done
(%i8) x; /* The value of x is not destroyed */
(%o8) [a,b,c]
(%i9) %o6; /* %o6 is a copy of the list */
(%o9) [a,b,c,x]
(%i10) %o5; /* But not %o5, the first entry is missing */
(%o10) [b,c,x]
But we can do it the following way too:
(%i13) y:copy(values);
(%o13) [b,c,x]
(%i14) kill(b);
(%o14) done
We have killed b, but the values of y and %o13 are not modified,
(%i15) y;
(%o15) [b,c,x]
(%i16) %o13;
(%o16) [b,c,x]
So, if we have a bug we might support a function to pass a copy of the
list to the user. Furthermore, it might be desirable to hide the
internal global list from access by the user.
If the current behavior is not a bug, it might be sufficient to document
it and give a hint to use the function copy if a real copy is necessary.
Dieter Kaiser