@@ -208,14 +208,14 @@ reference to a type `T` in subsequent phases to a type-splice, by rewriting `T`
208208For instance, the user-level definition of ` to ` :
209209
210210``` scala
211- def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ], Quotes ): Expr [T => R ] =
211+ def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ])( using Quotes ): Expr [T => R ] =
212212 ' { (x : T ) => $ { f(' x ) } }
213213```
214214
215215would be rewritten to
216216
217217``` scala
218- def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ], Quotes ): Expr [T => R ] =
218+ def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ])( using Quotes ): Expr [T => R ] =
219219 ' { (x : t.Underlying ) => $ { f(' x ) } }
220220```
221221
@@ -239,6 +239,7 @@ enum Exp {
239239 case Var (x : String )
240240 case Let (x : String , e : Exp , in : Exp )
241241}
242+ import Exp ._
242243```
243244
244245The interpreted language consists of numbers ` Num ` , addition ` Plus ` , and variables
@@ -479,7 +480,7 @@ inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) }
479480private def powerCode (x : Expr [Double ], n : Expr [Int ])(using Quotes ): Expr [Double ] =
480481 n.value match
481482 case Some (m) => powerCode(x, m)
482- case None => ' { Math .pow($x, $y ) }
483+ case None => ' { Math .pow($x, $n.toDouble ) }
483484
484485private def powerCode (x : Expr [Double ], n : Int )(using Quotes ): Expr [Double ] =
485486 if (n == 0 ) ' { 1.0 }
@@ -621,6 +622,7 @@ Similarly to the `summonFrom` construct, it is possible to make implicit search
621622in a quote context. For this we simply provide ` scala.quoted.Expr.summon ` :
622623
623624``` scala
625+ import scala .collection .immutable .{ TreeSet , HashSet }
624626inline def setFor [T ]: Set [T ] = $ { setForExpr[T ] }
625627
626628def setForExpr [T : Type ](using Quotes ): Expr [Set [T ]] = {
@@ -770,11 +772,17 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using
770772trait Show [- T ] {
771773 def show (x : T ): String
772774}
775+ // in a different file
776+ given Show [Boolean ] {
777+ def show (b : Boolean ) = " boolean!"
778+ }
779+
780+ println(showMe " ${true }" )
773781```
774782
775783### Open code patterns
776784
777- Quote pattern matching also provides higher-order patterns to match open terms. If a quoted term contains a definition,
785+ Quoted pattern matching also provides higher-order patterns to match open terms. If a quoted term contains a definition,
778786then the rest of the quote can refer to this definition.
779787
780788``` scala
0 commit comments