2
$\begingroup$

I am new to Mathematica so I do apologize if my question is too elementary.

In the start of my notebook, I want to make sure that any previous definitions are wiped out so I use the Quit[] or Exit[]command before any other commands.

For example, consider the following

Quit[]
g = 1/2 Sqrt[1 - v + 4 v^2]
g[[2,1]]

then I change last part of the code and I want to re-evaluate the whole cells (I know that I can just re-evaluate the last cell by pressing Shift+Enter but I don't want to do this as in long codes there are many such cells and I don't want to re-evaluate them one by one)

Quit[]
g = 1/2 Sqrt[1 - v + 4 v^2]
g[[2]]

So I press ctrl+A to select the whole cells and then press Shift+Enter to evaluate the cells or I use Evaluate Notebook in the Evaluation menu bar. But the problem is that the result does not change! I think that there may be a problem in my evaluation method.


Question

1- Can you kindly help me out to solve this issue? :)

2- What is the evaluation sequence in a NoteBook? For example, does it begin with the first cell? and then continues to evaluate the following cells in order.

$\endgroup$
7
  • 2
    $\begingroup$ Evaluating Quit[] clears the evaluation queue so the first command in the Notebook stops everything. It is not usually necessary to continually quit the kernel and re-evaluate entire notebooks but if you must, use, e.g., separate menu selections to (1) quit the kernel and (2) re-evaluate the notebook without the Quit[]. $\endgroup$ Mar 1, 2016 at 15:56
  • $\begingroup$ @MikeLimaOscar: Do you mean to just use the options in the Evaluation menu bar? and not using the command Quit[]? :) $\endgroup$ Mar 1, 2016 at 16:06
  • 1
    $\begingroup$ Exactly, I don't think I ever use Quit in a notebook. Kill the kernel as needed via the menu, then c-a shift-enter. As you learn good code practices you wont need to kill the kernel so often. $\endgroup$
    – george2079
    Mar 1, 2016 at 16:07
  • 1
    $\begingroup$ Also, if you do need to make a clean start every time ClearAll["Global`*"] takes care of most things, and much faster than killing/restarting the kernel. $\endgroup$
    – george2079
    Mar 1, 2016 at 16:11
  • 1
    $\begingroup$ If you are doing advanced things, such as modifying system functions then clearing the global context doesn't reset those things. $\endgroup$
    – george2079
    Mar 1, 2016 at 16:23

1 Answer 1

1
$\begingroup$

A useful principle in using the Wolfram Language: Remove values you assign to variables as soon as you finish using them. See Defining Variables.

How to Work with Variables and Functions

Variables and functions are integral to the Wolfram Language's symbolic programming language. These "How tos" give step-by-step instructions for common tasks related to variables, functions, and functional programming.

How to | Clear My Definitions

When you set a value to a symbol, that value will be used for the symbol for the entire Wolfram System session. Since symbols no longer in use can introduce unexpected errors when used in new computations, clearing your definitions is very desirable.

so ClearAll["Global`*"] is a proper way: ClearAll.

$\endgroup$

Your Answer

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

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