Runtime evaluation: Difference between revisions

Content added Content deleted
(adding maxima)
Line 374: Line 374:
typeof bar; // 'string'
typeof bar; // 'string'
</lang>
</lang>
=={{header|Maxima}}==

<lang maxima>/* Here is how to create a function and return a value at runtime. In the first example,
the function is made global, i.e. it still exists after the statement is run. In the second example, the function
is declared local. The evaluated string may read or write any variable defined before eval_string is run. */

kill(f)$

eval_string("block(f(x) := x^2 + 1, f(2))");
5

fundef(f);
/* f(x) := x^2 + 1 */

eval_string("block([f], local(f), f(x) := x^3 + 1, f(2))");
9

fundef(f);
/* f(x) := x^2 + 1 */</lang>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
The ooRexx INTERPRET instruction allows execution of dynamically constructed code. Almost any well-formed code can be executed dynamically, including multiple instructions at a time. The instructions are executed in the local context where the interpret instruction executes, so full access to the current variable context is available. For example:
The ooRexx INTERPRET instruction allows execution of dynamically constructed code. Almost any well-formed code can be executed dynamically, including multiple instructions at a time. The instructions are executed in the local context where the interpret instruction executes, so full access to the current variable context is available. For example: