Runtime evaluation/In an environment: Difference between revisions
Content added Content deleted
(Scala solution added) |
|||
Line 880: | Line 880: | ||
<code>eval</code> can then use the local variable <code>x</code> in this context. |
<code>eval</code> can then use the local variable <code>x</code> in this context. |
||
=={{header|Scala}}== |
|||
<lang Scala>object Eval extends App { |
|||
def evalWithX(expr: String, a: Double, b: Double)= |
|||
{val x = b; eval(expr)} - {val x = a; eval(expr)} |
|||
println(evalWithX("Math.exp(x)", 0.0, 1.0)) |
|||
}</lang> |
|||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
Almost identical to the [[Common Lisp]] version above. |
Almost identical to the [[Common Lisp]] version above. |
||
Line 886: | Line 895: | ||
(at-b (eval `(let ((x ',b)) ,prog)))) |
(at-b (eval `(let ((x ',b)) ,prog)))) |
||
(- at-b at-a)))</lang> |
(- at-b at-a)))</lang> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |