# Why doesn't ReplaceAll work in this situation? [closed]

I can work around this by using With, but it seems really odd to get the following:

PrimeQ[2]
PrimeQ[x] /. x -> 5
With[{x = 5}, PrimeQ[x]]
*True*
*False*
*True*


Obviously there is a logical explanation. But what is it?

• Because PrimeQ[x] is evaluated first, yielding False, so eventually you're doing False /. x->5. – corey979 Feb 6 '19 at 12:34
• PrimeQ has the rather undesireable property that it evaluates to False on symbolic input (which is bad because at this point, the question is actually undecidable.). ReleaseHold[Hold[PrimeQ[x]] /. x -> 5] works better. – Henrik Schumacher Feb 6 '19 at 12:35
• Gotcha. Thanks. – Richard Burke-Ward Feb 6 '19 at 12:40
• @HenrikSchumacher I disagree that PrimeQ's behaviour is undesirable: the general design of Q functions that they are meant to resolve to boolean values under all circumstances (with some annoying exceptions like FileExistsQ, which doesn't evaluate for non-strings). Programming in WL would be very tedious if the Q functions didn't follow this rule. You just need to keep that in mind when doing symbolic computations. – Sjoerd Smit Feb 6 '19 at 16:29
• @SjoerdSmit You make a very good point. The Q-function are not seldomly used in argument patterns for functions (e.g. as _?NumberQ). This might also be the reason why it is Positive and not PositiveQ. – Henrik Schumacher Feb 6 '19 at 16:43