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: | Line 1: | ||
{{task}} Given a program in the language |
{{task}} Given a program in the language with a free variable named <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]]. |
For more general examples and language-specific details, see [[Eval]]. |
||
Line 79: | Line 83: | ||
=={{header|Metafont}}== |
=={{header|Metafont}}== |
||
{{incorrect|Metafont|Either do not use a global variable, or note that this is impossible.}} |
|||
<lang metafont>string p; |
<lang metafont>string p; |
||
p := "2x + 1"; |
p := "2x + 1"; |
||
Line 89: | Line 96: | ||
=={{header|Octave}}== |
=={{header|Octave}}== |
||
{{incorrect|Octave|Either do not use a global variable, or note that this is impossible.}} |
|||
<lang octave>p = "x .* 2"; |
<lang octave>p = "x .* 2"; |
||
Line 112: | Line 121: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
{{incorrect|PHP|Either do not use a global variable, or note that this is impossible.}} |
|||
<lang php><?php |
<lang php><?php |
||
Line 166: | Line 177: | ||
=={{header|Tcl}}== |
=={{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 |
<lang tcl>package require Tcl 8.5 |
||