I have the Symbol e
with some upvalues and ownvalues:
f[e] = 1;
g[e] = 2;
e = 3;
I would like the evaluator to evaluate the definitions in that order. Currently, I get
f[e]
(* f[3] *)
I want
f[e]
(* 1 *)
The evaluator applies the ownvalues before the downvalues, this is documented. I want it to apply the downvalues first, then use the ownvalues. I'm sure there's some clever way of making this happen, I can't imagine this is too uncommon, but perhaps it is. I would prefer a solution that doesn't rely on $Pre, but beggers can't be choosers. The most ideal would be some attribute/thing I can attach to the symbol e
itself.
There's a number of related posts on the topic of nonstandard evaluation but I have been unable to glean a solution from them: 40165, 106068, 95087, 40165, 189014, 155480, 19067.
Additionally the documentation doesn't really discuss this as far as I can tell: guide, tutorials.
Edit Ok, I feel like the answers given give me enough to work with on my own. I had thought of trying a conditional ownvalue but didn't know how to implement it. Leonid Shifrin's solution shows how, and confirms my suspicions that it is an inefficient and fragile solution. Nonetheless, I don't think there is too much need to keep it open, and I will accept Leonid's solution and Michael E2's attribute method (which I probably should have thought of myself). Thanks for the help yall.
SetAttributes[f, HoldAll]
etc., but it's probably not what you want. $\endgroup$f
org
, but that is not actually the end of the world if I have to. Thanks, I didn't know that would work. I guess I haven't studied the function attributes documentation enough :) $\endgroup$whatever /. e->3
. It is up to you but if need to change the evaluation process then maybe something else should be changed. $\endgroup$