Re: Deleting Selective DownValues
- To: mathgroup at smc.vnet.net
- Subject: [mg64007] Re: [mg63985] Deleting Selective DownValues
- From: "Carl K. Woll" <carlw at wolfram.com>
- Date: Fri, 27 Jan 2006 05:13:18 -0500 (EST)
- References: <200601260843.DAA22213@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
David Park wrote:
> I think I found the solution for deleting definitions with a given number of arguments. The trick was to change the function name to stop evaluation.
>
> deleteDownValue[label_Symbol, numberOfArgs_Integer?Positive] :=
> Module[{g},
> DownValues[f] =
> Select[DownValues[f],
> Length[First[#] /. label -> g /. HoldPattern -> Identity] !=
> numberOfArgs &];]
>
> Clear[f]
> f[x_, y_, z_] := x y z
> f[a_, b_] := a b
> f[x_] := x
> DownValues[f]
> deleteDownValue[f, 2]
> DownValues[f]
>
> {HoldPattern[f[x_, y_, z_]] :> x y z, HoldPattern[f[a_, b_]] :> a b,
> HoldPattern[f[x_]] :> x}
>
> {HoldPattern[f[x_, y_, z_]] :> x y z, HoldPattern[f[x_]] :> x}
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
David,
Here's another idea:
deletedv[f_, n_] := DownValues[f] = DeleteCases[DownValues[f],
(Verbatim[HoldPattern][_[x__]] :> _)
/; Length[{x}] == n]
Carl Woll
Wolfram Research
- References:
- Deleting Selective DownValues
- From: "David Park" <djmp@earthlink.net>
- Deleting Selective DownValues