You needed Evaluate
because you want evaluation of an argument that is normally held, both in the case of ContourPlot
and Table
. There are several ways to force this evaluation.
Evaluate
causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare:Hold[Evaluate[2 + 2], 3 + 3]
andHold[5 + Evaluate[2 + 2]]
. (Hold
is used as a representative of an arbitrary function with theHoldAll
attribute.)Some functions such as
Plot
(andFindRoot
) can use the optionEvaluated -> True
-- for these this is superior to other methods because the range variable is still correctly localized.You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using
&
:
Hold[1 + 2 + #] &[2 + 2]
This works because the&
function evaluates its argument beforeHold
ever sees it, and#
(Slot
) can appear anywhere in the body of the function, not merely the first level.As Rojo stated you can use
With
to do a lexical replacement of specific variables:With[{x = 2 + 2}, Hold[x, 3 + 3]]
More complicated evaluations and insertion may be achieved using the methods I described herethe methods I described here.
Example using the pure function method:
W1 = {p, -2, 2, 0.5};
P = W1;
ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]