Group Abstract Group Abstract

Message Boards Message Boards

0
|
8K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Clear values of functions that remember values they have found?

Posted 10 years ago

How can i clear values saved by "Function That Remember Values They Have Found" without clearing the definition of the function? I have problems with memory usage. For example:

In:

f[x_] := f[x] =x^2;

f[0];

f[1];

?f

Out:

Global`f

f[0]=0

f[1]=1 

f[x_]:=f[x]=x^2

I want to clear all of the saved values (without specifying the values) and have this

In:

?f

Out:

Global`f

f[x_]:=f[x]=x^2

Thank you

POSTED BY: Arkadiy Ukupnik
4 Replies
Posted 10 years ago

You can use DownValues[] to reset. Try the following, one cell at a time:

f[x_] := f[x] =x^2;

f /@ Range[10]

?f

DownValues[f] = Take[DownValues[f], -1];

?f
POSTED BY: J. M.
Posted 10 years ago
POSTED BY: Alexey Popkov
Posted 10 years ago
POSTED BY: Arkadiy Ukupnik
Posted 10 years ago

Hm. I think i've found a decision.

f[x_] := f[x] = x^3;
DumpSave["dump.mx", f];
f[0];
f[1];
f[2];
f[3];
?f
Print["======="]
Clear[f]
?f
Print["======="]
<< dump.mx
?f

Out:

Global`f

f[0]=0

f[1]=1

f[2]=8

f[3]=27

f[x_]:=f[x]=x^3


=======

Global`f

=======

Global`f

f[x_]:=f[x]=x^3
POSTED BY: Arkadiy Ukupnik
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard