Consider
expr = Hold[1 + a + x + b + c + y + z];
idxes = {{1, 3}, {1, 4}};
Q1. I don't understand why
MapAt[Framed, expr, idxes]
works, but
MapAt[(Framed[#]) &, expr, idxes]
does not. Is there a problem with using pure functions with MapAt? Or is it Hold that causes troubles?
Q2. More in general, I would like to pass the position n in MapAt also as a parameter inside f. More precisely, in the following MWE consider how to rewrite the last line
expr = Hold[1 + a + x + b + c + y + z];
idxes = {{1, 3}, {1, 4}};
color = {{RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1], RGBColor[1, 1, 0]}};
tmp = MapAt[Framed, expr, idxes];
tmp /. Framed[p_] :> EventHandler[Framed[p], "MouseDown" :> (CurrentValue[EvaluationCell[], Background] = Extract[color, Position[tmp, Framed[p]]][[1]])]
avoiding to having to re-evaluate Position[tmp, Framed[p]], which actually gives the position previously specified in idxes. I thought something like
MapAt[(EventHandler[Framed[#], "MouseDown" :> (CurrentValue[EvaluationCell[], Background] = Extract[color, #][[1]])])& , expr, idxes]
worked, but it does not.