MathGroup Archive 1995

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

Search the Archive

Clearing values

  • To: mathgroup at
  • Subject: [mg2053] Clearing values
  • From: Allan Hayes <hay at>
  • Date: Mon, 18 Sep 1995 01:50:36 -0400

I attach some comments (3) on the reply (2), to the following query  
(1).  I'm not sure of the source of (2).

(1) Query from: rutter at (Michael A. Rutter)

>Does anybody know a simple command to clear all the variables and  
>functions in a Mathematica session.  We have been using Clear /@
>Names["Global`*"], but since we are teaching a freshman level  
Calc>course, this is difficult to explain.

(2) Reply(I'm not sure of the source of this)

This has been discussed before on this group - basically, Clear is  
the only clean way to do it; you can clothe it in some nicely-named  
convenience function but that's about all.

In my experience, it's generally better to tell students to quit  
and start again. Pretty low tech, you might say, but there are  
several advantages:

1) it helps to convince timid students that the computer won't  
break if you do something drastic like quitting, and that is still  
quite a common attitude with British students (exposure to computers  
in schools is still patchy)

2) it encourages the habit of frequently saving work you want to  
keep, as insurance against software crashes (and even Mathematica on  
a big PowerMac will still do that if you confuse it enough).

3) memory problems with Mathematica are often associated with front  
end memory (say, you're doing lots of 3D graphics) and Clear'ing  
out the kernel doesn't help that at all.


(3) Comments

I find that the simplest way is to use Clear["`*"], which clears  
all definitions for terms in the current context (usually  
ClearAll["`*"] will, in addition, clear attribute assignments.
To do a morethhrooghhcllarrng, iincluding clearing loaded packages,  
you can use CleanSlate[] from the package CleanSlate`, which can be  
made to load automatically when the kernel is loaded (if you want  
to suppress information and hide output then arrange for  
SetOptions[CleanSlate, Verbose -> False] to be loaded automatically  
when the kernel is loaded and put ; after CleasnSlate[]).

I do not like to use quit and restart as a way of clearing because:

1.It gives students the impression that using the system is clumsy  
and time-consuming (which is especially undesirable for those  
relatively unfamiliar with computers)

2.Many times we just want to clear the definitions tagged by  
certain symbols (for which Clear[f,g,...] can be used) or  
definitions with a specific right hand side (for which rhs = . can  
be used).

3.The objectives of clearing definitions and clearing memory (which  
may certainly need a restart, as noted in (2) 3 ) are different.

The need to save frequently in order to avoid loss can be  
demonstrated by showing that closing the kernel throws away all  
stored user definitions and that quitting also looses all unsaved  
material from the notebook -- the lesson will undoubtedly be  
reinforced the hard way!

Fear of breaking the system can be countered by quitting Mma,by  
closing down the machine and by even switching power off and then  
showing that all is well. Also by getting students to try to change  
the definition of a system function (eg by entering Sin[6] = 7) and  
letting them find that this is not possible(without unprotecting  

Allan Hayes
De Monfort University Leicester UK
hay at

  • Prev by Date: Re: Mathematica and NetScape
  • Next by Date: MMA for finance/econometrics
  • Previous by thread: Re: New user question?
  • Next by thread: MMA for finance/econometrics