How can you Unset the following UpValues?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite
3












This expression is taken from a talk given by the late Robby Villegas. The UpValues to some symbol a is defined below as:



ClearAll["a"];
a /: _[___, a, ___] := (Print["a fired"]; Null)


Nothing I tried could Clear the definitions associated with the symbol. Is there a way to clear the associated UpValues.







share|improve this question


















  • 4




    Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
    – Leonid Shifrin
    Sep 8 at 17:33














up vote
8
down vote

favorite
3












This expression is taken from a talk given by the late Robby Villegas. The UpValues to some symbol a is defined below as:



ClearAll["a"];
a /: _[___, a, ___] := (Print["a fired"]; Null)


Nothing I tried could Clear the definitions associated with the symbol. Is there a way to clear the associated UpValues.







share|improve this question


















  • 4




    Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
    – Leonid Shifrin
    Sep 8 at 17:33












up vote
8
down vote

favorite
3









up vote
8
down vote

favorite
3






3





This expression is taken from a talk given by the late Robby Villegas. The UpValues to some symbol a is defined below as:



ClearAll["a"];
a /: _[___, a, ___] := (Print["a fired"]; Null)


Nothing I tried could Clear the definitions associated with the symbol. Is there a way to clear the associated UpValues.







share|improve this question














This expression is taken from a talk given by the late Robby Villegas. The UpValues to some symbol a is defined below as:



ClearAll["a"];
a /: _[___, a, ___] := (Print["a fired"]; Null)


Nothing I tried could Clear the definitions associated with the symbol. Is there a way to clear the associated UpValues.









share|improve this question













share|improve this question




share|improve this question








edited Sep 8 at 17:44









Carl Woll

56.3k272147




56.3k272147










asked Sep 8 at 14:22









Ali Hashmi

5,49931330




5,49931330







  • 4




    Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
    – Leonid Shifrin
    Sep 8 at 17:33












  • 4




    Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
    – Leonid Shifrin
    Sep 8 at 17:33







4




4




Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
– Leonid Shifrin
Sep 8 at 17:33




Regardless of the method to solve this problem, I will mention that giving such generic UpValues to symbols is outright dangerous. Speaking from experience here, I have tried to use this kind of rules before, and it was invariably biting me later - so I never ended up leaving such constructs in final code in whatever I was doing.
– Leonid Shifrin
Sep 8 at 17:33










2 Answers
2






active

oldest

votes

















up vote
9
down vote













Note that you could clear all of the *Values by using Clear["a"] or ClearAll["a"]. However, if you only want to clear this particular UpValues you could make use of the fact that HoldAllComplete prevents UpValues from firing. So, temporarily give TagUnset this attribute. Here's your UpValues definition:



ClearAll["a"];
a /: _[___,a,___] := (Print["a fired"];Null)


Give TagUnset the HoldAllComplete attribute, and unset the above definition:



Internal`InheritedBlock[TagUnset,
SetAttributes[TagUnset, HoldAllComplete];
TagUnset[a, _[___,a,___]]
]


Check:



UpValues[a]









share|improve this answer






















  • Thanks. Very neat.
    – Ali Hashmi
    2 days ago

















up vote
6
down vote













a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null);

f[a]
(* a fired *)

(* As we can see below, usage of ClearAll does not work *)

ClearAll[a]
(* a fired *)


(* now removing the associated values using the TagUnset Head *)

TagUnset[Unevaluated[a],HoldPattern[Except[TagUnset, _][___, a, ___]]];

f[a]
(* f[a] *)





share|improve this answer




















  • I think both the Unevaluated and the HoldPattern are unnecessary.
    – Carl Woll
    Sep 9 at 6:48










  • @Carl .. though unnecessary but I think it is a safe practice
    – Ali Hashmi
    2 days ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181496%2fhow-can-you-unset-the-following-upvalues%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
9
down vote













Note that you could clear all of the *Values by using Clear["a"] or ClearAll["a"]. However, if you only want to clear this particular UpValues you could make use of the fact that HoldAllComplete prevents UpValues from firing. So, temporarily give TagUnset this attribute. Here's your UpValues definition:



ClearAll["a"];
a /: _[___,a,___] := (Print["a fired"];Null)


Give TagUnset the HoldAllComplete attribute, and unset the above definition:



Internal`InheritedBlock[TagUnset,
SetAttributes[TagUnset, HoldAllComplete];
TagUnset[a, _[___,a,___]]
]


Check:



UpValues[a]









share|improve this answer






















  • Thanks. Very neat.
    – Ali Hashmi
    2 days ago














up vote
9
down vote













Note that you could clear all of the *Values by using Clear["a"] or ClearAll["a"]. However, if you only want to clear this particular UpValues you could make use of the fact that HoldAllComplete prevents UpValues from firing. So, temporarily give TagUnset this attribute. Here's your UpValues definition:



ClearAll["a"];
a /: _[___,a,___] := (Print["a fired"];Null)


Give TagUnset the HoldAllComplete attribute, and unset the above definition:



Internal`InheritedBlock[TagUnset,
SetAttributes[TagUnset, HoldAllComplete];
TagUnset[a, _[___,a,___]]
]


Check:



UpValues[a]









share|improve this answer






















  • Thanks. Very neat.
    – Ali Hashmi
    2 days ago












up vote
9
down vote










up vote
9
down vote









Note that you could clear all of the *Values by using Clear["a"] or ClearAll["a"]. However, if you only want to clear this particular UpValues you could make use of the fact that HoldAllComplete prevents UpValues from firing. So, temporarily give TagUnset this attribute. Here's your UpValues definition:



ClearAll["a"];
a /: _[___,a,___] := (Print["a fired"];Null)


Give TagUnset the HoldAllComplete attribute, and unset the above definition:



Internal`InheritedBlock[TagUnset,
SetAttributes[TagUnset, HoldAllComplete];
TagUnset[a, _[___,a,___]]
]


Check:



UpValues[a]









share|improve this answer














Note that you could clear all of the *Values by using Clear["a"] or ClearAll["a"]. However, if you only want to clear this particular UpValues you could make use of the fact that HoldAllComplete prevents UpValues from firing. So, temporarily give TagUnset this attribute. Here's your UpValues definition:



ClearAll["a"];
a /: _[___,a,___] := (Print["a fired"];Null)


Give TagUnset the HoldAllComplete attribute, and unset the above definition:



Internal`InheritedBlock[TagUnset,
SetAttributes[TagUnset, HoldAllComplete];
TagUnset[a, _[___,a,___]]
]


Check:



UpValues[a]










share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 8 at 17:20

























answered Sep 8 at 16:50









Carl Woll

56.3k272147




56.3k272147











  • Thanks. Very neat.
    – Ali Hashmi
    2 days ago
















  • Thanks. Very neat.
    – Ali Hashmi
    2 days ago















Thanks. Very neat.
– Ali Hashmi
2 days ago




Thanks. Very neat.
– Ali Hashmi
2 days ago










up vote
6
down vote













a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null);

f[a]
(* a fired *)

(* As we can see below, usage of ClearAll does not work *)

ClearAll[a]
(* a fired *)


(* now removing the associated values using the TagUnset Head *)

TagUnset[Unevaluated[a],HoldPattern[Except[TagUnset, _][___, a, ___]]];

f[a]
(* f[a] *)





share|improve this answer




















  • I think both the Unevaluated and the HoldPattern are unnecessary.
    – Carl Woll
    Sep 9 at 6:48










  • @Carl .. though unnecessary but I think it is a safe practice
    – Ali Hashmi
    2 days ago














up vote
6
down vote













a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null);

f[a]
(* a fired *)

(* As we can see below, usage of ClearAll does not work *)

ClearAll[a]
(* a fired *)


(* now removing the associated values using the TagUnset Head *)

TagUnset[Unevaluated[a],HoldPattern[Except[TagUnset, _][___, a, ___]]];

f[a]
(* f[a] *)





share|improve this answer




















  • I think both the Unevaluated and the HoldPattern are unnecessary.
    – Carl Woll
    Sep 9 at 6:48










  • @Carl .. though unnecessary but I think it is a safe practice
    – Ali Hashmi
    2 days ago












up vote
6
down vote










up vote
6
down vote









a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null);

f[a]
(* a fired *)

(* As we can see below, usage of ClearAll does not work *)

ClearAll[a]
(* a fired *)


(* now removing the associated values using the TagUnset Head *)

TagUnset[Unevaluated[a],HoldPattern[Except[TagUnset, _][___, a, ___]]];

f[a]
(* f[a] *)





share|improve this answer












a /: Except[TagUnset, _][___, a, ___] := (Print["a fired"]; Null);

f[a]
(* a fired *)

(* As we can see below, usage of ClearAll does not work *)

ClearAll[a]
(* a fired *)


(* now removing the associated values using the TagUnset Head *)

TagUnset[Unevaluated[a],HoldPattern[Except[TagUnset, _][___, a, ___]]];

f[a]
(* f[a] *)






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 8 at 14:22









Ali Hashmi

5,49931330




5,49931330











  • I think both the Unevaluated and the HoldPattern are unnecessary.
    – Carl Woll
    Sep 9 at 6:48










  • @Carl .. though unnecessary but I think it is a safe practice
    – Ali Hashmi
    2 days ago
















  • I think both the Unevaluated and the HoldPattern are unnecessary.
    – Carl Woll
    Sep 9 at 6:48










  • @Carl .. though unnecessary but I think it is a safe practice
    – Ali Hashmi
    2 days ago















I think both the Unevaluated and the HoldPattern are unnecessary.
– Carl Woll
Sep 9 at 6:48




I think both the Unevaluated and the HoldPattern are unnecessary.
– Carl Woll
Sep 9 at 6:48












@Carl .. though unnecessary but I think it is a safe practice
– Ali Hashmi
2 days ago




@Carl .. though unnecessary but I think it is a safe practice
– Ali Hashmi
2 days ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181496%2fhow-can-you-unset-the-following-upvalues%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery