MathGroup Archive 1999

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

Search the Archive

Re: Deleting a DownValue, Evaluate[f@@argList]=. does not do it

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20796] Re: Deleting a DownValue, Evaluate[f@@argList]=. does not do it
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 14 Nov 1999 18:13:48 -0500 (EST)
  • References: <80au96$j2i@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Adalbert,

Some experiments:

(1) ------------ One-at-a-time setting and unsetting ---------------

Clear[f];
f[1] = 1;
f[2, 3] = 2;

?f

    Global`f
    f[1] = 1

    f[2, 3] = 2

Block[{f, Unset}, f @@ {2, 3} =.]

?f

    Global`f
    f[1] = 1

( we had to block f to stop it evaluating f[2,] to 1 immediately - this is
what gave the problem that you found; and we had to block Unnset so that it
did not hold its entry as f@@{1})

We can also use a pure function:

(f[##] =.) & @@ {1};

?f

Global`f

(2)  ----------- Lists of inputs and values -------------------

    - two ways (a) using Block, (b) using a pure function

(a) Using Block

Clear[f]
Block[{Set, f}, f @@@ {{1}, {2, 3}, {4}, {5}} = {1, 2, 3, 4}];

?f

Global`f
f[1] = 1

f[4] = 3

f[5] = 4

f[2, 3] = 2

Block[{Unset, f}, f @@@ {{2, 3}, {5}} =.];

?f

Global`f
f[1] = 1

f[4] = 3

*Note*: Unset[{e1,e2 ..}] unsets each of e1, e2 ...  .

(b) Using a pure function

Clear[f]
MapThread[(f[Sequence @@ #1] = #2) &, {{{1}, {2, 3}, {4}, {5}}, {1, 2, 3,
4}}];

?f

    Global`f
    f[1] = 1

    f[4] = 3

    f[5] = 4

    f[2, 3] = 2

(f[##] =.) & @@@ {{2, 3}, {5}};

?f

    Global`f
    f[1] = 1

    f[4] = 3

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

<hanssen at zeiss.de> wrote in message news:80au96$j2i at smc.vnet.net...
> Hi, MathGroup,
>
> f[1]=1;
> f[2]=2;
> ?f
>
> yields
>
> "Global`f"
> f[1] = 1
> f[2] = 2
>
> now get rid of definition for 1
>
> f[1]=.;
> ?f
>
> yields
>
> "Global`f"
> f[2] = 2
>
>
> So far, it works as expected. I want to memorize results for combinations
of arguments
> like f[a,b,c]=results and so on. To do this, I write f@@argList. Now I
demonstrate
> this on lists with length 1, to make it simple. When making the
assignment, it has to be
> wrapped in Evaluate:
>
> Clear[f];
> Evaluate[f@@{1}]=1;
> Evaluate[f@@{2}]=2;
> ?f
>
> yields
>
> "Global`f"
> f[1] = 1
> f[2] = 2
>
> as before. Now I want to get rid of the definition for 1 in the analogous
way:
>
> Evaluate[f@@{1}]=.
>
> yields
>
> Unset::usraw: Cannot unset raw object !
> $Failed
>
> How to proceed without searching through DownValues[f] and deleting
> the one meant - very awkward?
>
> kind regards
>
> Dipl.-Math. Adalbert Hanszen
>




  • Prev by Date: Help with geometry problem required.
  • Next by Date: Re: Re: Multidimensional Splines/Interpolation ?
  • Previous by thread: Re: Deleting a DownValue, Evaluate[f@@argList]=. does not do it
  • Next by thread: Graphics output