Is it possible to localize an assignment to an expression (defined via UpSet) instead of a Symbol within a scoping construct?

It would be nice if I had something like the following at my disposal:

Block[{f[1,2]=ab}, (*<-- what I need*)

(I need to use Block. Module and With are not correct for my case.)


1 Answer 1


If you need to preserve the definitions of a Symbol with exception(s) to some particular case(s) you should use Internal`InheritedBlock:

f[a_, b_] := a + b;

Internal`InheritedBlock[{f}, f[1, 2] := ab;
 Table[f[i, j], {i, 1, 2}, {j, 1, 2}]]

f[1, 2]
{{2, ab}, {3, 4}}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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