How can you Unset the following UpValues?
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
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.
function-construction pattern-matching
add a comment |Â
up vote
8
down vote
favorite
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.
function-construction pattern-matching
4
Regardless of the method to solve this problem, I will mention that giving such genericUpValues
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
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
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.
function-construction pattern-matching
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.
function-construction pattern-matching
function-construction pattern-matching
edited Sep 8 at 17:44
Carl Woll
59k277151
59k277151
asked Sep 8 at 14:22
Ali Hashmi
5,50431330
5,50431330
4
Regardless of the method to solve this problem, I will mention that giving such genericUpValues
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
add a comment |Â
4
Regardless of the method to solve this problem, I will mention that giving such genericUpValues
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
add a comment |Â
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]
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
add a comment |Â
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] *)
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
Sep 9 at 20:05
add a comment |Â
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]
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
add a comment |Â
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]
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
add a comment |Â
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]
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]
edited Sep 8 at 17:20
answered Sep 8 at 16:50
Carl Woll
59k277151
59k277151
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
add a comment |Â
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
Thanks. Very neat.
â Ali Hashmi
Sep 9 at 20:04
add a comment |Â
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] *)
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
Sep 9 at 20:05
add a comment |Â
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] *)
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
Sep 9 at 20:05
add a comment |Â
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] *)
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] *)
answered Sep 8 at 14:22
Ali Hashmi
5,50431330
5,50431330
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
Sep 9 at 20:05
add a comment |Â
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
Sep 9 at 20:05
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
Sep 9 at 20:05
@Carl .. though unnecessary but I think it is a safe practice
â Ali Hashmi
Sep 9 at 20:05
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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