File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,13 @@ prints it again in an error message if it evaluates to `false`.
2929 inline def assert(expr: => Boolean): Unit =
3030 ~ assertImpl('(expr))
3131
32- def assertImpl(expr: Expr[Boolean]) =
33- '{ if !(~expr) then throw new AssertionError(s"failed assertion: ${~showExpr(expr)}") }
32+ def assertImpl(expr: Expr[Boolean]) = '{
33+ if !(~expr) then
34+ throw new AssertionError(s"failed assertion: ${~showExpr(expr)}")
35+ }
36+
37+ def showExpr(expr: Expr[Boolean]): Expr[String] =
38+ '("<some source code>") // Better implementation later in this document
3439
3540If ` e ` is an expression, then ` '(e) ` or ` '{e} ` represent the typed
3641abstract syntax tree representing ` e ` . If ` T ` is a type, then ` '[T] `
@@ -587,9 +592,12 @@ analogue of lifting.
587592
588593Using lifting, we can now give the missing definition of ` showExpr ` in the introductory example:
589594
590- def showExpr[T](expr: Expr[T]): Expr[String] = expr.toString
595+ def showExpr[T](expr: Expr[T]): Expr[String] = {
596+ val code = expr.show
597+ code.toExpr
598+ }
591599
592- That is, the ` showExpr ` method converts its ` Expr ` argument to a string, and lifts
600+ That is, the ` showExpr ` method converts its ` Expr ` argument to a string ( ` code ` ) , and lifts
593601the result back to an ` Expr[String] ` using the implicit ` toExpr ` conversion.
594602
595603## Implementation
You can’t perform that action at this time.
0 commit comments