Topic variable: Difference between revisions

Added Mathematica
(Added Mathematica)
Line 76:
 
Multiple references to the current input are allowed, e.g. [.,.] constructs an array of length two, each component being equal to the current input; thus the compound expression "1 | [.,.]" yields [1,1].
 
=={{header|Mathematica}}==
This depends on the Mathematica REPL. For the examples, I will use the textual format that Mathematica provides. Here's some basic examples:
<pre>In[1]:= 3
 
Out[1]= 3
 
In[2]:= %1^2
 
Out[2]= 9
 
In[3]:= Sqrt[%%]
 
Out[3]= Sqrt[3]
 
In[4]:= N[Out[-1]] (* for floating point *)
 
Out[4]= 1.73205</pre>
In this, I use 3 different forms. Here's a list of them:
* %<n>: Does the same as Out[n].
* %, %%, %%%, etc.: Does the same as Out[-<number of %s>].
* Out[n]: Returns the output of the nth cell.
* Out[-n]: Returns the output of the nth to last cell, excluding the one that it is in. (Out[-1] gives last output, -2 gives second to last, etc.)
* In[n]: Reevaluates and returns the input of the nth cell.
* In[-n]: Reevaluates and returns the input of the nth to last cell.
When an input is reevaluated, it also reassigns all relative Ins and Outs. Look at this for an example of its strange effects:
<pre>In[1]:= In[2]
 
Out[1]= In[2]
 
In[2]:= In[1]
 
$IterationLimit::itlim: Iteration limit of 4096 exceeded.
 
Out[2]= Hold[In[1]]</pre>
In it, it gets stuck in an infinite loop between In[1] and In[2], which evaluate to each other.
 
=={{header|Oforth}}==