Runtime evaluation: Difference between revisions

Added Mathematica
(Added Mathematica)
Line 670:
typeof bar; // 'string'
</lang>
 
=={{header|Mathematica}}==
Mathematica's <code>ToExpression</code> evaluates an expression string as if it were placed directly in the code. Statements are just <code>CompoundExpression</code>s, so they also work. Any evaluation can be limited with <code>TimeConstrained</code> and <code>MemoryConstrained</code>.
<lang Mathematica>Print[ToExpression["1 + 1"]];
Print[ToExpression["Print[\"Hello, world!\"]; 10!"]];
x = 5;
Print[ToExpression["x!"]];
Print[ToExpression["Module[{x = 8}, x!]"]];
Print[MemoryConstrained[ToExpression["Range[5]"], 10000, {}]];
Print[MemoryConstrained[ToExpression["Range[10^5]"], 10000, {}]];
Print[TimeConstrained[ToExpression["Pause[1]; True"], 2, False]];
Print[TimeConstrained[ToExpression["Pause[60]; True"], 2, False]];</lang>
{{out}}
<pre>2
Hello, world!
3628800
120
40320
{1, 2, 3, 4, 5}
{}
True
False</pre>
 
=={{header|MATLAB}}==