Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to have a ReplaceAll applied to every output in my notebook. When I try this using $Post, e.g. by writing

$Post = /.{i^2 -> -1}

it doesn't work. Anyone know an alternative?

share|improve this question

closed as too localized by Oleksandr R., Ajasja, Artes, J. M. Nov 5 '12 at 3:20

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Does $Post = (# /. {i^2 -> -1}) & do the job? –  J. M. Oct 31 '12 at 13:01
yes! thanks. what does the extra syntax do? –  popffabrik Oct 31 '12 at 13:40
Voting to close as too localized because, as @halirutan's answer shows, a close reading of the documentation would have been entirely sufficient to provide the answer. –  Oleksandr R. Oct 31 '12 at 16:07

1 Answer 1

up vote 9 down vote accepted

You have to read the documentation carefully:

$Post is a global variable whose value, if set, is applied to every output expression.

The important word is applied because it suggests, that you have to give a function which takes the output and does something with it. Knowing this, you could have started to search the Documentation Center for function or, if you already knew it, to write down such a Function

Function[output, output /. i^2 -> -1]

Then you look at the first 3 examples in the documentation of Function and you instantly see, that there are different equivalent forms:

Function[u, 3 + u][x]

Function[3 + #][x]

(3 + #) &[x]

The rest is, to read and study the documentation carefully.

Another approach would have been, to take the hint J.M. gave you and look at its FullForm

(* Function[ReplaceAll[Slot[1],List[Rule[Power[i,2],-1]]]] *)

There, you would have seen, that the only unknown things to you are Function and Slot. Again, use the Documentation Center and read the the help-pages.

share|improve this answer

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