Closed
Description
To be able to use var
we need to extend Expr[T]
with a VarExpr[T]
that allows the expression to be used in the left-hand side of an expression.
def whileNotZero(body: VarExpr[Int] => Expr[Unit]) = '{
var x = 0
while (x == 0) ~body('(x))
}
whileNotZero(x => '{ ~x = ~x - 1 })
Currently in '{ ~x = ~x - 1 }
, the left hand side cannot be spliced in. The VarExpr[T]
would allow x to be spliced on the left hand side of the assignment.