Jump to content

Runtime evaluation/In an environment: Difference between revisions

Added Kotlin
(Added Kotlin)
Line 518:
 
<lang javascript>evalWithX('Math.exp(x)', 0, 1) // returns 1.718281828459045</lang>
 
=={{header|Kotlin}}==
{{trans|JavaScript}}
When you try to compile the following program, it will appear to the compiler that the local variable 'x' is assigned but never used and warnings will be issued accordingly. You can get rid of these warnings by compiling using the -nowarn flag.
<lang scala>// 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))
}</lang>
 
{{out}}
<pre>
1.718281828459045
</pre>
 
=={{header|Liberty BASIC}}==
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.