Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Clear all variables but not functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122195] Re: Clear all variables but not functions
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 20 Oct 2011 07:43:17 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 10/19/11 at 5:34 AM, mailcwc at gmail.com wrote:

>I define some functions in the init.m that starts with Mathematica.
>How do I clear all variables but not these functions in the init.m?

>I am also confused about the differences among Remove, Clear,
>ClearAll, and Quit. Are there some cases that one function is
>preferred than others.

Clear[f] would clear any definitions and values assigned to f
but would not clear any defaults, options or attributes assigned
to f.

ClearAll[f] clears options, defaults and attributes assigned to
f as well as values and definitions.

Neither Clear nor ClearAll actually remove the things cleared.
That is, if you do

f[x_]:=2 x
Clear[f]
?Global`*

You will see f is still one of the symbols in the Global context.

Remove[f] actually removes f. That is do

f[x_]:=2 x
Remove[f]
?Global`*

and f will not be found in the Global context

Quit quits the kernel. This will remove all symbols, reset the
In/Out stack etc. Basically, all evaluation that Mathematica
does ends when you Quit.

And since none of these do exactly the same thing, there will be
times when one is preferred over the others.




  • Prev by Date: continuous updating
  • Next by Date: Re: simplification
  • Previous by thread: Clear all variables but not functions
  • Next by thread: Does CUDAImageConvolve work on lists?