Sometimes I'd like to make a function, which would take an argument "by reference" instead of usual "by value". This is semantically similar to what e.g. AppendTo does: changes the variable passed to it. But when I try to do this straightforwardly, I get:
myFunc[x_] := (Clear[x]; x = 1)
test = 0; (* dirty the variable *)
myFunc[test];
Clear::ssym: 0 is not a symbol or a string. >>
Set::setraw: Cannot assign to raw object 0. >>
So, seems x is treated as "the value of x" inside the function. How do I change myFunc to treat x as "the symbol passed as x", so that it works like intended?
{a,b,c}=f[a,b,c]is really convenient. After all, even the built-inAppendTo[v,val]is also nothing more than syntactic sugar overv=Append[v,val], but it's so useful. This can be compared to usingx+=yinstead ofx=x+y. – Ruslan Jan 28 '15 at 09:37nth column andnth row in each, so a functionzeroCross[mat_,n_]would just do that. I'd then just dozeroCross[#,n]&/@{m1,m2,...,mk}. If it returned the changed matrix instead of changing the argument, this would change to{m1,m2,...,mk}=zeroCross[#,n]&/@{m1,m2,...,mk}, wheremkis of course not a two-letter name. – Ruslan Jan 28 '15 at 09:45