Runtime evaluation/In an environment: Difference between revisions

Content added Content deleted
(→‎{{header|Octave}}: ++ metafont)
(clarify task: mention not using a global variable, avoid the 'provided code is a function' interpretation)
Line 1:
{{task}} Given a program in the language representingwith a function of thefree variable <var>x</var>, evaluate it withnamed <var>x</var> (or another name if that is not valid syntax), evaluate it with <var>x</var> bound to a provided value, then evaluate it again with <var>x</var> bound to another provided value, then subtract the result of the first from the second and return or print it.
 
Do so in a way which:
Preferably, do so in a way which does not involve string manipulation of source code, and is plausibly extensible to a runtime-chosen set of bindings.
* does not involve string manipulation of source code
* is plausibly extensible to a runtime-chosen set of bindings rather than just <var>x</var>
* does not make <var>x</var> a ''global'' variable
or note that these are impossible.
 
For more general examples and language-specific details, see [[Eval]].
Line 79 ⟶ 83:
 
=={{header|Metafont}}==
 
{{incorrect|Metafont|Either do not use a global variable, or note that this is impossible.}}
 
<lang metafont>string p;
p := "2x + 1";
Line 89 ⟶ 96:
 
=={{header|Octave}}==
 
{{incorrect|Octave|Either do not use a global variable, or note that this is impossible.}}
 
<lang octave>p = "x .* 2";
Line 112 ⟶ 121:
 
=={{header|PHP}}==
 
{{incorrect|PHP|Either do not use a global variable, or note that this is impossible.}}
 
<lang php><?php
Line 166 ⟶ 177:
 
=={{header|Tcl}}==
 
{{incorrect|Tcl|The code provided should not itself be a function, but have x as a free variable.}}
 
<lang tcl>package require Tcl 8.5