Bug introduced in 10.1 and fixed in 10.2
I wanted to roll a function that works like /.
but only acts on the very first match it encounters.
ReplaceAtFirst =
Function[{expr, rule},
MapAt[Replace[#, rule] &, expr, FirstPosition[expr, First@rule]]]
to demonstrate, how the replacement rule works in this question.
ReplaceAtFirst[x^3 + 2 y, _Symbol -> 1]
(* 1[x^3, 2 y] *)
ReplaceAtFirst[%, _Symbol -> 1]
(* Kernel crashes *)
Upon further investigation, it appears, that
MapAt[# /. {_Symbol -> 1} &, 1[x], {1}]
also crashes the kernel. It appears, that an integer or rational head in the expression 1[x]
leads to a crash. Replacing 1.0[x]
to 1.0[1]
works fine.
Using ReplacePart
or other replacement functions directly, without MapAt
also works fine.
Is this a known problem? I am using MMA 10.1 on Win7x64 enterprise.