@@ -65,12 +65,14 @@ is treated as a quote `'{x}`. See the Syntax section below for details.
6565
6666Quotes and splices are duals of each other. For arbitrary
6767expressions ` e ` and types ` T ` we have:
68- ```
68+
69+ ``` scala
6970$ {' {e}} = e
7071' {$ {e}} = e
7172$ {' [T ]} = T
7273' [$ {T }] = T
7374```
75+
7476### Types for Quotations
7577
7678The type signatures of quotes and splices can be described using
@@ -202,11 +204,14 @@ For instance, the user-level definition of `to`:
202204def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ], Quotes ): Expr [T => R ] =
203205 ' { (x : T ) => $ { f(' x ) } }
204206```
207+
205208would be rewritten to
209+
206210``` scala
207211def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ], Quotes ): Expr [T => R ] =
208- ' { (x : t.Underlying } ) => $ { f(' x ) } }
212+ ' { (x : t.Underlying ) => $ { f(' x ) } }
209213```
214+
210215The ` summon ` query succeeds because there is a given instance of
211216type ` Type[T] ` available (namely the given parameter corresponding
212217to the context bound ` : Type ` ), and the reference to that value is
@@ -328,7 +333,6 @@ def showExpr[T](expr: Expr[T])(using Quotes): Expr[String] = {
328333That is, the ` showExpr ` method converts its ` Expr ` argument to a string (` code ` ), and lifts
329334the result back to an ` Expr[String] ` using ` Expr.apply ` .
330335
331-
332336### Lifting Types
333337
334338The previous section has shown that the metaprogramming framework has
@@ -612,6 +616,7 @@ val b: String = defaultOf("string")
612616```
613617
614618### Defining a macro and using it in a single project
619+
615620It is possible to define macros and use them in the same project as long as the implementation
616621of the macros does not have run-time dependencies on code in the file where it is used.
617622It might still have compile-time dependencies on types and quoted code that refers to the use-site file.
@@ -622,7 +627,6 @@ If there are any suspended files when the compilation ends, the compiler will au
622627compilation of the suspended files using the output of the previous (partial) compilation as macro classpath.
623628In case all files are suspended due to cyclic dependencies the compilation will fail with an error.
624629
625-
626630### Pattern matching on quoted expressions
627631
628632It is possible to deconstruct or extract values out of ` Expr ` using pattern matching.
@@ -712,7 +716,6 @@ def f(exp: Expr[Any])(using Quotes) =
712716
713717This might be used to then perform an implicit search as in:
714718
715-
716719``` scala
717720extension (inline sc : StringContext ) inline def showMe (inline args : Any * ): String = $ { showMeExpr(' sc , ' args ) }
718721
@@ -744,7 +747,8 @@ trait Show[-T] {
744747
745748Quote pattern matching also provides higher-order patterns to match open terms. If a quoted term contains a definition,
746749then the rest of the quote can refer to this definition.
747- ```
750+
751+ ``` scala
748752' {
749753 val x : Int = 4
750754 x * x
@@ -785,6 +789,6 @@ eval { // expands to the code: (16: Int)
785789We can also close over several bindings using ` $b(a1, a2, ..., an) ` .
786790To match an actual application we can use braces on the function part ` ${b}(a1, a2, ..., an) ` .
787791
788-
789792### More details
793+
790794[ More details] ( ./macros-spec.md )
0 commit comments