2
$\begingroup$

I can't describe exactly the problem I'm experiencing, but this kind of problem has a remarkable feature, that is, commands which couldn't work in the before can be executed correctly when i turn off the Mathematica and reopen it. Later, I know function "Clear[]", it can also solve this kind problem in the most occasions. But sometimes it's not very convenient to use Clear[] for multiple variables. I think this kind problem probably has something to do with the naming of variables and the life cycle and scope, and I want to ask 1. if there are some good habits to avoid such problems, and 2. whether there is a way to solve it other than restart Mathematica.

$\endgroup$
4
  • 2
    $\begingroup$ Clear["Global`*"] will clear all symbols in the Global context $\endgroup$
    – Bob Hanlon
    Commented Dec 28, 2022 at 20:43
  • 1
    $\begingroup$ If I'm in that sort of experimental phase where I keep changing my function definitions, I'll sometimes end up adding DownValues when I intended to replace DownValues. If I realize that I may be in this cycle for awhile, I'll just put a ClearAll in front of my definitions. So, if I'm defining myFunc[...]:=..., I'll change it to ClearAll[myFunc];myFunc[...]:=.... Then, each time I make a change and re-evaluate that cell, I know I'm starting from a "clean slate". Typically I'll remove these superfluous ClearAlls when things have settled. $\endgroup$
    – lericr
    Commented Dec 28, 2022 at 22:25
  • 1
    $\begingroup$ Welcome to the Mathematica Stack Exchange. The introductory book written by the inventor is a good learning resource. There is a fast intro for math students as well as a fast intro for programmers to choose from. In this particular case, you can include a minimal example (using Mathematica code, not an image) to get more focused replies. Thanks. $\endgroup$
    – Syed
    Commented Dec 29, 2022 at 0:59
  • 2
    $\begingroup$ Another important thing is, one should always keep an eye on the color of the variable. If a variable is empty, it's blue, otherwise it's black. $\endgroup$
    – xzczd
    Commented Dec 29, 2022 at 2:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.