Skip to content

Quoted var assignment #3878

Closed
Closed
@nicolasstucki

Description

@nicolasstucki

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions