indirect subscripted variable assignment



On 2012-07-02, J?rome Laurens <jerome.laurens at u-bourgogne.fr> wrote:

> given a[1] and b[1], I want a function f such that f(a) will set a[1]
> to some value whereas f(b) will set b[1] to the same value.

Use the undocumented (sorry, I guess) function arraysetapply here.

(%i1) f(x):= arraysetapply (x, [1], 12345);
(%o1)                f(x) := arraysetapply(x, [1], 12345)
(%i2) f(a);
(%o2)                                12345
(%i3) a[1];
(%o3)                                12345
(%i4) f(b);
(%o4)                                12345
(%i5) b[1];
(%o5)                                12345

HTH

Robert Dodier