This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
 Mathematica Tutorial Functions »|Tutorials »

# Dialogs

Within a standard interactive session, you can create "subsessions" or dialogs using the Mathematica command Dialog. Dialogs are often useful if you want to interact with Mathematica while it is in the middle of doing a calculation. As mentioned in "Tracing Evaluation", TraceDialog for example automatically calls Dialog at specified points in the evaluation of a particular expression. In addition, if you interrupt Mathematica during a computation, you can typically "inspect" its state using a dialog.
 Dialog[] initiate a Mathematica dialog Dialog[expr] initiate a dialog with expr as the current value of % Return[] return from a dialog, taking the current value of % as the return value Return[expr] return from a dialog, taking expr as the return value

Initiating and returning from dialogs.

 This initiates a dialog.
You can do computations in a dialog just as you would in any Mathematica session.
 Out[2]=
 Out[3]=
When you exit a dialog, you can return a value for the dialog using Return[expr]. If you do not want to return a value, and you have set , then you can also exit a dialog simply by giving an end-of-file character, at least on systems with text-based interfaces.
 To evaluate this expression, Mathematica initiates a dialog.
The value a+b returned from the dialog is now inserted in the original expression.
 Out[5]=
In starting a dialog, you will often find it useful to have some "initial expression". If you use Dialog[expr], then Mathematica will start a dialog, using expr as the initial expression, accessible for example as the value of %.
This first starts a dialog with initial expression a^2.
 Out[6]=
% is the initial expression in the dialog.
 Out[7]=
This returns a value from the first dialog, and starts the second dialog, with initial expression b+c.
 Out[8]=
This returns a value from the second dialog. The final result is the original expression, with values from the two dialogs inserted.
 Out[9]=
Dialog effectively works by running a subsidiary version of the standard Mathematica main loop. Each dialog you start effectively "inherits" various values from the overall main loop. Some of the values are, however, local to the dialog, so their original values are restored when you exit the dialog.
Thus, for example, dialogs inherit the current line number \$Line when they start. This means that the lines in a dialog have numbers that follow the sequence used in the main loop. Nevertheless, the value of \$Line is local to the dialog. As a result, when you exit the dialog, the value of \$Line reverts to what it was in the main loop.
If you start a dialog on line 10 of your Mathematica session, then the first line of the dialog will be labeled In[11]. Successive lines of the dialog will be labeled In[12], In[13] and so on. Then, when you exit the dialog, the next line in your main loop will be labeled In[11]. At this point, you can still refer to results generated within the dialog as Out[11], Out[12] and so on. These results will be overwritten, however, when you reach lines In[12], In[13], and so on in the main loop.
In a standard Mathematica session, you can tell whether you are in a dialog by seeing whether your input and output lines are indented. If you call a dialog from within a dialog, you will get two levels of indentation. In general, the indentation you get inside d nested dialogs is determined by the output form of the object DialogIndent[d]. By defining the format for this object, you can specify how dialogs should be indicated in your Mathematica session.
 DialogSymbols:>{x,y,...} symbols whose values should be treated as local to the dialog DialogSymbols:>{x=x0,y=y0,...} symbols with initial values DialogProlog:>expr an expression to evaluate before starting the dialog

Options for Dialog.

Whatever setting you give for DialogSymbols, Dialog will always treat the values of \$Line, \$Epilog and \$MessageList as local. Note that if you give a value for \$Epilog, it will automatically be evaluated when you exit the dialog.
When you call Dialog, its first step is to localize the values of variables. Then it evaluates any expression you have set for the option DialogProlog. If you have given an explicit argument to the Dialog function, this is then evaluated next. Finally, the actual dialog is started.
When you exit the dialog, you can explicitly specify the return value using Return[expr]. If you do not do this, the return value will be taken to be the last value generated in the dialog.