Skip to content

Commit 8a06372

Browse files
Merge pull request #10555 from ShapelessCat/fix-docs
Fix docs
2 parents 69b451b + d7ee4eb commit 8a06372

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

docs/docs/reference/contextual/extension-methods.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension (x: String)
4040
extension (x: Elem)
4141
def +: (xs: Seq[Elem]): Seq[Elem] = ...
4242
extension (x: Number)
43-
@infix def min (y: Number): Number = ...
43+
infix def min (y: Number): Number = ...
4444

4545
"ab" < "c"
4646
1 +: List(2, 3)
@@ -52,7 +52,7 @@ The three definitions above translate to
5252
```scala
5353
<extension> def < (x: String)(y: String): Boolean = ...
5454
<extension> def +: (xs: Seq[Elem])(x: Elem): Seq[Elem] = ...
55-
@infix <extension> def min(x: Number)(y: Number): Number = ...
55+
infix <extension> def min(x: Number)(y: Number): Number = ...
5656
```
5757

5858
Note the swap of the two parameters `x` and `xs` when translating
@@ -113,6 +113,7 @@ extension (ss: Seq[String]):
113113
```
114114

115115
The same can be written with braces as follows (note that indented regions can still be used inside braces):
116+
116117
```scala
117118
extension (ss: Seq[String]) {
118119

@@ -239,11 +240,13 @@ The following two rewritings are tried in order:
239240
from `T` to a type containing `m`. If there is more than one way of rewriting, an ambiguity error results.
240241

241242
An extension method can also be referenced using a simple identifier without a preceding expression. If an identifier `g` appears in the body of an extension method `f` and refers to an extension method `g` that is defined in the same collective extension
243+
242244
```scala
243245
extension (x: T)
244246
def f ... = ... g ...
245247
def g ...
246248
```
249+
247250
the identifier is rewritten to `x.g`. This is also the case if `f` and `g` are the same method. Example:
248251

249252
```scala
@@ -261,7 +264,6 @@ def position(s: String)(ch: Char, n: Int): Int =
261264
else n
262265
```
263266

264-
265267
### Syntax
266268

267269
Here are the syntax changes for extension methods and collective extensions relative

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)