File tree 1 file changed +12
-4
lines changed
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`.
29
29
inline def assert(expr: => Boolean): Unit =
30
30
~ assertImpl('(expr))
31
31
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
34
39
35
40
If ` e ` is an expression, then ` '(e) ` or ` '{e} ` represent the typed
36
41
abstract syntax tree representing ` e ` . If ` T ` is a type, then ` '[T] `
@@ -587,9 +592,12 @@ analogue of lifting.
587
592
588
593
Using lifting, we can now give the missing definition of ` showExpr ` in the introductory example:
589
594
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
+ }
591
599
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
593
601
the result back to an ` Expr[String] ` using the implicit ` toExpr ` conversion.
594
602
595
603
## Implementation
You can’t perform that action at this time.
0 commit comments