function argument overwriitten?



Maxima passes lists and matrices as objects, not as values. So if you modify
them within your function, they are modified globally.

          -s

On Fri, May 22, 2009 at 9:28 AM, Rob Burns <rob_g_burns at yahoo.co.uk> wrote:

>
> This seems like an error to me....
>
> What's going on here?
> Create a function..
> (%i6) f(v):=block([t],t:v,t[1]:99,t);
> (%o6) f(v):=block([t],t:v,t[1]:99,t)
> (%i7) a:[1,2,3];
> (%o7) [1,2,3]
> and execute it
> (%i8) m:f(a);
> (%o8) [99,2,3]
> it has worked ok...
> (%i9) m;
> (%o9) [99,2,3]
> BUT the source operand has been overwritten !!
> (%i10) a;
> (%o10) [99,2,3]
>
> Also the same thing happened when I mistakenly put a for v in the
> definituion of f()
>
> Create a function..
> (%i1) f(v):=block([t],t:a,t[1]:99,t);
> (%o1) f(v):=block([t],t:a,t[1]:99,t)
> (%i2) a:[1,2,3];
> (%o2) [1,2,3]
> and execute it
> (%i3) m:f(a);
> (%o3) [99,2,3]
> it has worked ok...
> (%i4) m;
> (%o4) [99,2,3]
> BUT the source operand has been overwritten !!
> (%i5) a;
> (%o5) [99,2,3]
>
> Am I missing something?
> Regards, Rob.
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>