Runtime evaluation/In an environment: Difference between revisions

Content added Content deleted
(clarify wording of task)
(add E example)
Line 28:
(- at-b at-a)))
</lang>
 
=={{header|E}}==
<lang e># Constructing an environment has to be done by way of evaluation for historical reasons which will hopefully be entirely eliminated soon.
def bindX(value) {
def [resolver, env] := e`
def x # bind x and capture its resolver and the resulting environment
`.evalToPair(safeScope)
resolver.resolve(value) # set the value
return env
}
 
def evalWithX(program, a, b) {
def atA := program.eval(bindX(a))
def atB := program.eval(bindX(b))
return atB - atA
}</lang>
 
<lang e>? evalWithX(e`(x :float64).exp()`, 0, 1)
# value: 1.7182818284590455</lang>
 
=={{header|Forth}}==