Runtime evaluation/In an environment: Difference between revisions

Content added Content deleted
(clarify task: mention not using a global variable, avoid the 'provided code is a function' interpretation)
(→‎{{header|Octave}}: changed into an imitation of python, more or less)
Line 97: Line 97:
=={{header|Octave}}==
=={{header|Octave}}==


<lang octave>function r = calcit(f, val)
{{incorrect|Octave|Either do not use a global variable, or note that this is impossible.}}
x = val;
r = eval(f);
endfunction

p = "x .* 2";
a = calcit(p, [1:3]);
b = calcit(p, [4:6]);


<lang octave>p = "x .* 2";
x = [1:3];
a = eval(p);
x = [4:6];
b = eval(p);
disp(b-a);</lang>
disp(b-a);</lang>