Message Boards Message Boards

0
|
51427 Views
|
13 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Difference between Clear and ClearAll, and between '* and Global`* ?

Posted 11 years ago
What is the difference between 'Clear' and ClearAll'  and between "`*" and "Global`*"  I have used ClearAll["Global`*"]  and values remain attached to variables.   What is the easiest way to clear all values to all variables going forward?????
POSTED BY: Raymond Low
13 Replies
Posted 27 days ago

I'm not sure where I got the idea that:

ClearAll["Global*`"]

should work but somehow I did get that idea:

What works:

ClearAll["Global`*"]
POSTED BY: James Bowery

I usually use an inelegant brute force method to clear all variables and definitions: Quit Kernel followed by Evaluate Notebook. Sometimes there is some hidden code lurking in a notebook. This is also eliminated.

POSTED BY: S M Blinder

I did a quick notebook and typed in x =1 and hit enter. Then typed in Quit Kernel and hit enter. Then I typed in x and a value of 1 showed up.
Am I missing something? Jake

POSTED BY: Jake Trexel

After you select Quit Kernel (from the Evaluation menu) do you follow up by clicking on Local in the sidebar?

POSTED BY: S M Blinder

No I didn't. I did not use the drop down menus at all. I just typed it in.
Jake

POSTED BY: Jake Trexel

That worked great, wish I had seen it a long time ago. Thanks for your help.

Jake

POSTED BY: Jake Trexel

I read through all of the posts to this subject and still don't understand what will work and what will not work. For an example I have an equation that uses 12 constants. My first line I put in all of the symbols and there values that I want to use. Example, rowna=1;rowcl=2;rowk=3; and keep on going until I have all of them listed with values. Them I put in my equation and run it. If I want to I can then can go back into my first line and change what I want too.
But if I want to get rid of all of these assigned values, what do I do. I know that I could use the Clear command and list every constant that I used, but it takes time and its easy to make a mistake.
Is there any way to clear out all variables that I have assigned values to for each section of a book that I am writing. I always end up getting caught with an old value that I forgot to clear out?

Thanks Jake

POSTED BY: Jake Trexel
a) That is interesting.  There could be a context issue left over from a package or notebook setting.

What do ?a and $Context give?  On my 9.0.1 on Macintosh,

In[1]:= a=1;

In[2]:= ?a

    Global`a
    a=1

In[3]:= ClearAll["Global`*"];
           a

Out[4]= a

In[5]:= $Context
Out[5]= Global`

In[6]:= ?a

   Global`a


b) "Global`\.1d*"  probably means that some non-printing character slipped in between the back-tick and the asterisk.
Try re-typing that line.

c) Usually := is used for function definitions so the variables on the right-hand side are not given values until the function is called with arguments defined.
= is used for almost everything else, since the assignment might as well happen once, right away.

q:=7  means that every time q is used, the assignment of 7 to q is re-done.
POSTED BY: Bruce Miller
Posted 11 years ago
Hi Bruce Miller, now it works, thanks a lot!

a) & b):
You were right, there was a space after the " ` " character. The " ` " is a bit cumbersome to type on the German keyboard, and requires a space, or arrow right afterwards. I did not delete the space, and didn't notice it, since it was not displayed.
So ClearAll works perfect now, thanks a lot!

c) I see, thanks!

I'd have one further question: What the syntax "Global`*" actually mean, so I can remember it more easilly? (Especially the `* part.)
POSTED BY: Gernot H
Posted 11 years ago
Hi, thanks for the answer!

For example,
a=1;
ClearAll["Global`*"];
a
gives the output
1

When I try it with Remove, I get the error message:
Remove::rmnsm: There are no symbols matching "Global`\.1d*". >>

As a little side question: I am not sure if I am supposed to use := or = for assigning values to variables, or for function definitions.
POSTED BY: Gernot H
Could you give a simple example of a case where 
ClearAll["Global`*"]

does not work?  Remember that this only ClearAll's symbols in the Global` context.  If you have other contexts with symbols those will not get cleared. 

As a more complete approach you can use 
Remove["Global`*"]
POSTED BY: David Reiss
Posted 11 years ago
Hi,

I am having essentially the same question. I want to find a way to clear all variable assignments and function definitions I made in a document so far. Neither
ClearAll["Global`*"]
nor
Clear["Global`*"]
work. Accourding to the Mathematica help they should.

What is the proper command?
POSTED BY: Gernot H
Clear removes values and definitions from a symbol while ClearAll removes attributes, messages and any default options as well as values and definitions from a symbol.

The * kind of has the same meaning it does on a unix terminal, meaning any set of characters of any length. Global` is a particular context. It happens to be the default context when you are making definitions in a notebook. When you use the command
ClearAll["Global`*"]
you are removing all definitions, values attributes, messages and default options that have been created in the Global` context and that don't have the Protected attribute.

You can read more on this at

    http://reference.wolfram.com/mathematica/ref/Clear.html
    http://reference.wolfram.com/mathematica/ref/ClearAll.html
    http://reference.wolfram.com/mathematica/tutorial/Contexts.html
    http://reference.wolfram.com/mathematica/ref/Protected.html
POSTED BY: Jason Grigsby
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract