Dialogs

Within a standard interactive session, you can create "subsessions" or dialogs using the Wolfram Language command Dialog. Dialogs are often useful if you want to interact with the Wolfram Language 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 the Wolfram Language during a computation, you can typically "inspect" its state using a dialog.

Dialog[]initiate a Wolfram Language 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.
In[1]:=
Click for copyable input
You can do computations in a dialog just as you would in any Wolfram Language session.
In[2]:=
Click for copyable input
Out[2]=
You can use Return to exit from a dialog.
In[3]:=
Click for copyable input
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 $IgnoreEOF=False, then you can also exit a dialog simply by giving an endoffile character, at least on systems with textbased interfaces.

To evaluate this expression, the Wolfram Language initiates a dialog.
In[4]:=
Click for copyable input
The value returned from the dialog is now inserted in the original expression.
In[5]:=
Click for copyable input
Out[5]=

In starting a dialog, you will often find it useful to have some "initial expression". If you use Dialog[expr], then the Wolfram Language 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 .
In[6]:=
Click for copyable input
Out[6]=
is the initial expression in the dialog.
In[7]:=
Click for copyable input
Out[7]=
This returns a value from the first dialog, and starts the second dialog, with initial expression .
In[8]:=
Click for copyable input
Out[8]=
This returns a value from the second dialog. The final result is the original expression, with values from the two dialogs inserted.
In[9]:=
Click for copyable input
Out[9]=

Dialog effectively works by running a subsidiary version of the standard Wolfram Language 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 of your Wolfram Language 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 Wolfram Language 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 Wolfram Language 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:>expran 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.