Skip to content

Commit 4e93ea7

Browse files
committed
Remove an unmatched close brace
1 parent 85e48f7 commit 4e93ea7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ is treated as a quote `'{x}`. See the Syntax section below for details.
6565

6666
Quotes and splices are duals of each other. For arbitrary
6767
expressions `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

7678
The type signatures of quotes and splices can be described using
@@ -202,11 +204,14 @@ For instance, the user-level definition of `to`:
202204
def 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+
205208
would be rewritten to
209+
206210
```scala
207211
def 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+
210215
The `summon` query succeeds because there is a given instance of
211216
type `Type[T]` available (namely the given parameter corresponding
212217
to 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] = {
328333
That is, the `showExpr` method converts its `Expr` argument to a string (`code`), and lifts
329334
the result back to an `Expr[String]` using `Expr.apply`.
330335

331-
332336
### Lifting Types
333337

334338
The 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+
615620
It is possible to define macros and use them in the same project as long as the implementation
616621
of the macros does not have run-time dependencies on code in the file where it is used.
617622
It 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
622627
compilation of the suspended files using the output of the previous (partial) compilation as macro classpath.
623628
In 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

628632
It 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

713717
This might be used to then perform an implicit search as in:
714718

715-
716719
```scala
717720
extension (inline sc: StringContext) inline def showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
718721

@@ -744,7 +747,8 @@ trait Show[-T] {
744747

745748
Quote pattern matching also provides higher-order patterns to match open terms. If a quoted term contains a definition,
746749
then 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)
785789
We can also close over several bindings using `$b(a1, a2, ..., an)`.
786790
To 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

Comments
 (0)