Often I have a desire to create variables that are bound to an if statement. Some calculations refer only to a certain statement βifβ - it smells bad for contamination of the external area with temporary variables.
What I would like to do:
val data = (whatever) if (val x = data*2+5.4345/2.45; val y = data/128.4; x*y < 10) x * y else x * 2 println(x) //ERROR!
One of the options is pretty messy:
val data = (whatever) if (data*2+5.4345/2.45*data/128.4 < 10) data*2+5.4345/2.45*data/128.4 else data*2+5.4345/2.45 * 2
The explicit alternative I'm trying to avoid is:
val data = (whatever) val x = data*2+5.4345/2.45 val y = data/128.4 if (x*y < 10) x*y else x * 2 println(x) //OK
Is this possible in Scala? Is there a decent solution? If not, what other languages ββsupport this idea?
scala
vertexshader
source share