I am constructing matrices whose elements are lists themselves (of varying length), and am (re)setting the entries of these matrices using among others the "All" command. It seems that in this context, Mathematica's commands are not well-defined: for a vector A,
A[[All]] = x
in general sets all entries of A equal to x, except when x is a vector of the same length as A, in which case it instead gets interpreted to mean A = x.
As a concrete example,
A={a,b};
A[[All]]={1,2,3};
yields A as
{{1,2,3},{1,2,3}}
while
B={a,b};
B[[All]]={1,2};
yields B as
{1,2}
I realize the general behavior can be reproduced in the special case by using Hold[] in the evaluation, as in e.g.
F={a,b};
F[[All]]=Hold[{1,2}];
F=ReleaseHold[F];
which yields F as
{{1,2},{1,2}}
but I find this rather clunky.
Has anybody encountered this or related issues before and come up with a more elegant alternative?
I would also welcome any explanation as to why this behavior may actually be considered desirable (as opposed to allowing for e.g. an "Every" option in addition to "All"), or comments as to why other constructions (e.g. functions) are the more appropriate tool in Mathematica in this context.