x
x
x


Do so in a way which:

 does not involve string manipulation of the input source code
 is plausibly extensible to a runtime-chosen set of bindings rather than just x
 does not make x a global variable


or note that these are impossible.



See also

 For more general examples and language-specific details, see Eval.
 Dynamic variable names is a similar task.


// Kotlin JS version 1.1.4-3
 
fun evalWithX(expr: String, a: Double, b: Double) {
    var x = a
    val atA = eval(expr)
    x = b
    val atB = eval(expr)
    return atB - atA
}
 
fun main(args: Array<String>) {
    println(evalWithX("Math.exp(x)", 0.0, 1.0))
}