I apologize if the title is too vague/general but I couldn't find a better one. I am trying to use either Module or With but it does not work if the object containing the local variables is defined outside of Module or With. Here is an example that does not work:
f = Cos[qx + qy];
With[{qy = qx},
f
]
which gives:
Cos[qx + qy]
but this obviously works:
With[{qy = qx},
Cos[qx + qy]
]
and gives:
Cos[2 qx]
What am I missing? I could define f as a function and that would work. But I would like to understand why this scoping does not work while it works in other languages.
With[{qy = qx}, Evaluate[f]]
$\endgroup$Trace
to look at the evaluation process of both with and withoutEvaluate
. $\endgroup$With
/Module
/Block
scoping. $\endgroup$