18 lines
501 B
Plaintext
18 lines
501 B
Plaintext
/* 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 */
|