If I am creating an arithmetic problem solving app, is it a bad idea to use an eval function to have Kotlin evaluate the result of an expression, like
Copy code
import javax.script.ScriptEngineManager
fun main() {
val engine = ScriptEngineManager().getEngineByName("kotlin")
val result = engine.eval("2 + 2 == 4")
...
?
This is to avoid having to implement my own recursive expression parser
c
CLOVIS
02/20/2024, 9:16 AM
Yes, it is a very bad idea. If you do this, your users will be able to execute arbitrary Kotlin code, not just expressions.
If that's what they want, they should just use