MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Deleting Selective DownValues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64012] Re: Deleting Selective DownValues
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 27 Jan 2006 05:13:26 -0500 (EST)
  • References: <dra3e7$m4s$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi David,

isn't this one a bit easier?

deleteDownValues[label_Symbol,numberOfArgs_Integer?Positive]:=
   Set[DownValues[label],
     Select[DownValues[label],Count[First[#],_Blank,3]!=numberOfArgs &]];

Clear[f]
f[x_,y_,z_]:=x y z
f[a_,b_]:=a b
f[x_]:=x
DownValues[f]
deleteDownValues[f,2]

-->
{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}

Cordially,
   Peter

David Park schrieb:
> 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/ 
> 


  • Prev by Date: When does Mathematica display a message?
  • Next by Date: Re: Deleting Selective DownValues
  • Previous by thread: Re: Deleting Selective DownValues
  • Next by thread: Electrical Power Systems