|
Contents | Previous | Next | Subchapters |
| Syntax |
eval(cmd) |
| See Also | execfile |
x = 5
eval("x = x + x")
print x
O-Matrix will respond
10
eval function will return a value when
cmd is an expression.
If you enter
y = eval("1 + 2")
print y
O-Matrix will respond
3
eval function will return
those values.
If you enter
clear
function [x, y] = f(a, b) begin
x = 2 * a
y = 2 * b
end
[u, v] = eval("f(1, 2)")
print u, v
O-Matrix will respond
2, 4
eval function references variables as if they were
in the currently executing file and function. If you enter
x = 1
function f() begin
x = 3
eval("x = x + x")
print x
end
f
O-Matrix will respond
6
when it executes the function f. If you continue by entering
x
O-Matrix will respond
1
because the variable x in the main program is different from the
variable x with in the function f.
eval function it cannot be used until after
the call is executed. If you enter
clear
begin
eval("a = 1")
eval("print a")
end
O-Matrix will respond
1
If on the other hand you enter
clear
begin
eval("a = 1")
print a
end
O-Matrix will respond with an error message saying that
the variable a is not yet defined at the print statement.
This is because the call to
the eval function has not yet been executed at
the time when the print statement is compiled.
eval
only the first command is executed.
If you enter
eval("print 1; print 2")
O-Matrix will respond
1