Possible Duplicate:
How to Set parts of indexed lists?
For better organization of my code, sometime I use data objects in the form:
data["A", "1"] = {{1, 2}, {3, 4}}
instead of
dataA1 = {{1, 2}, {3, 4}};
One of the advantages is when working with Module, because I can declare data just one time, and I can use data["A","1"], data["A","2"], data["B","1"] and so on, with limited scope.
Everything works fine except for one detail. With data["A", "1"] I can't perform operations like:
data["A", "1"] = {{1, 2}, {3, 4}}
data["A", "1"][[All, 2]] = "X"
to change data["A", "1"] to {{1, "X"}, {3, "X"}}
I got the error:
Set::setps: data["A", "1"] in the part assignment is not a symbol
When I try with:
dataA1 = {{1, 2}, {3, 4}};
dataA1[[All, 2]] = "X";
dataA1
I have no problem and get {{1, "X"}, {3, "X"}} as expected.
There is nome way to perform this kind of operation in data["A", "1"] object?
Update
The question indicated as duplicated do not handle the case: data["A", "1",...] but just data["A"]
data["A", "1"]they work for just one arg function. It's not the case to reopen it? Or it's simple to extend it fordata[__]case? – Murta Jan 25 '13 at 14:03sym[index_]withsym[indices__](of course, consistently across the bodies of the functions), and it should work, I think. Let me know if it does not. As for the answer of @Mr.Wizard, I suppose that should work for it too. – Leonid Shifrin Jan 25 '13 at 14:26