this is what i want:
scala> var x:Int = 10
x: Int = 10
scala> var y:Int = 20
y: Int = 20
scala> val ret = q"return $x>$y"
ret: universe.Return = return 10.$greater(20)
scala> val result1 = toolbox.compile(ret)()
result1: Any = false
But the problem is that I will be getting the expression $x>$y in a string var, like
scala> m
res20: String = $x>$y
And then I want to perform the operation as,
var ret = q"return $m"
but this return:
scala> var ret = q"return $m"
ret: universe.Return = return "$x>$y"
which is not serving the purpose. How can I get the value of x and y in the last step instead $x and $y.
You can mix quasiquotes and
ToolBox.parse
to achieve results mostly like what you are looking for:Making use of your values as variables:
If you evaluate
q"return ${toolbox.parse(m)}"
you will see the error becausex
andy
are not in scope.To fix that: