8
$\begingroup$

I just changed my default notebook context to 'unique to this Notebook' so that variables don't roll across numerous open notebooks. Doing this, however, made the command ClearAll["Global*"] stop working to clear all declared variables. I also tried, ClearAll[Evaluate[Context[] <> "*"]], but that didn't work either. Any ideas?

$\endgroup$

2 Answers 2

8
$\begingroup$

As soon as you set your notebook context to 'unique to this Notebook', the notebook's context is no longer Global`, but, well, unique to the notebook.

I can't test right now, but assuming you are not in an explicitly opened context (like after Begin or BeginPackage), I think the following should work:

ClearAll@@{$Context<>"*"}

At least it works in a kernel with manually changed $Context.

$\endgroup$
4
  • $\begingroup$ It works, so +1. $\endgroup$
    – rcollyer
    May 30, 2013 at 19:02
  • $\begingroup$ Awesome, totally works! Any ideas why variables aren't going back to blue (from black)? $\endgroup$ May 30, 2013 at 19:38
  • $\begingroup$ @zhermes: I have no idea. IIRC the variables actually already start out being black when the notebook uses its own context (can't check now); no idea why. Maybe the colouring algorithm doesn't take the different context into account correctly. $\endgroup$
    – celtschk
    May 30, 2013 at 19:47
  • 3
    $\begingroup$ I think you could just do ClearAll@"`*"... $\endgroup$
    – rm -rf
    May 31, 2013 at 3:21
3
$\begingroup$

I think instead of ClearAll["Global`*"], you can just Clear["`*"]. This should work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.