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.

  • $\begingroup$ None of your examples crash for me with mma v10.2.0 (OSX 10.9.5). $\endgroup$
    – SquareOne
    Oct 5, 2015 at 11:24
  • 1
    $\begingroup$ Yes, it crashes with 10.1, but not with 10.0 or 10.2. Tested on OS X. $\endgroup$
    – Szabolcs
    Oct 5, 2015 at 11:52
  • $\begingroup$ @Szabolcs It works on MMA 8.0 and MMA 10.2 under Win7x64. Looks like a bug introduced somewhere in between and resolved in 10.2 $\endgroup$
    – LLlAMnYP
    Oct 5, 2015 at 11:54

1 Answer 1


Bug introduced in 10.1 and fixed in 10.2

From the comments of @Szabolcs and @SquareOne:

Works under OS X in 10.0 and 10.2, but not in 10.1.

From my observations:

Works under Win7x64 in 8.0 and 10.2, but not 10.1.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.