This might be the result of some confusion on my part. I've tried to implement this without picking apart `expr` and then putting it back together again, which probably isn't the clearest way to do it.

The loop just below this bit walks down the heads of `expr`, setting `e` to each one, until we either get to the head that `n` specifies or we hit an atomic object. After the for loop, modifying `e.head` makes `expr` reflect the result we want. I put the `expr.copy()` in because I thought that otherwise, doing something like:

```
In[1]:= e = f[a][b][c]
Out[1]= f[a][b][c]

In[2]:= Operate[p, e, 2]
Out[2]= p[f[a]][b][c]
```

might end up modifying `e` behind the user's back, depending on how `expr` gets here and whether any references to it are stored anywhere else. I put the `expr = expr.copy()` line in to guard against this happening, but I just tried without the copy, and it looks like this case works fine, so it might not be necessary.