You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: overviews/macros/blackbox-whitebox.md
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ outof: 11
12
12
13
13
**Eugene Burmako**
14
14
15
-
Separation of macros into blackbox ones and whitebox ones is implemented in the recent milestone builds of Scala 2.11, starting from 2.11.0-M7. It is not implemented in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
15
+
Separation of macros into blackbox ones and whitebox ones is implemented in the recent milestone builds of Scala 2.11, starting from 2.11.0-M7 (however, in 2.11.0-M8, the syntax underwent some changes, so this documentation isn't applicable to earlier milestone builds of 2.11). The *box separation is not implemented in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
16
16
17
17
## Why macros work?
18
18
@@ -39,9 +39,7 @@ We recognize the importance of both blackbox and whitebox macros, however we fee
39
39
40
40
In the 2.11 release, we take first step of standardization by expressing the distinction between blackbox and whitebox macros in signatures of def macros, so that `scalac` can treat such macros differently. This is just a preparatory step, so both blackbox and whitebox macros remain experimental in Scala 2.11.
41
41
42
-
We express the distinction by replacing `scala.reflect.macros.Context` with `scala.reflect.macros.BlackboxContext` and `scala.reflect.macros.WhiteboxContext`. If a macro impl is defined with `BlackboxContext` as its first argument, then macro defs that are using it are considered blackbox, and analogously for `WhiteboxContext`. Of course, the vanilla `Context` is still there for compatibility reasons, but it issues a deprecation warning encouraging to choose between blackbox and whitebox macros.
43
-
44
-
[Macro bundles](/overviews/macros/bundles.html) also support the distinction by providing two different traits to inherit from: `scala.reflect.macros.BlackboxMacro` and `scala.reflect.macros.WhiteboxMacro`. Unsurprisingly, the former provides a `BlackboxContext` and turns its users into blackbox macros, and the latter provides a `WhiteboxContext` and makes def macros referring to it to be whitebox macros.
42
+
We express the distinction by replacing `scala.reflect.macros.Context` with `scala.reflect.macros.blackbox.Context` and `scala.reflect.macros.whitebox.Context`. If a macro impl is defined with `blackbox.Context` as its first argument, then macro defs that are using it are considered blackbox, and analogously for `whitebox.Context`. Of course, the vanilla `Context` is still there for compatibility reasons, but it issues a deprecation warning encouraging to choose between blackbox and whitebox macros.
45
43
46
44
Blackbox def macros are treated differently from def macros of Scala 2.10. The following restrictions are applied to them by the Scala typechecker:
Copy file name to clipboardExpand all lines: overviews/macros/bundles.md
+8-19Lines changed: 8 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ languages: [ja]
13
13
14
14
**Eugene Burmako**
15
15
16
-
Macro bundles are shipped with the recent milestone builds of Scala 2.11, starting from 2.11.0-M4. They are not available in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
16
+
Macro bundles are shipped with the recent milestone builds of Scala 2.11, starting from 2.11.0-M4 (however, in 2.11.0-M8, the syntax underwent some changes, so this documentation isn't applicable to earlier milestone builds of 2.11). Macro bundles are not available in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
2. Moreover, since macro parameters are path-dependent on the macro context, [special incantations](/overviews/macros/overview.html#writing_bigger_macros) are required to wire implementations and helpers together.
28
28
29
-
Macro bundles provide a solution to these problems by allowing macro implementations to be declared in traits, which extend
30
-
`scala.reflect.macros.BlackboxMacro` or `scala.reflect.macros.WhiteboxMacro`. These base traits predefine `val c: BlackboxContext`
31
-
and `val c: WhiteboxContext` correspondingly, relieving macro implementations from having to declare the context in their signatures,
32
-
which simplifies modularization.
29
+
Macro bundles provide a solution to these problems by allowing macro implementations to be declared in classes that take
30
+
`c: BlackboxContext` or `c: WhiteboxContext` as their constructor parameters, relieving macro implementations from having
31
+
to declare the context in their signatures, which simplifies modularization. Referencing macro implementations defined in bundles
32
+
works in the same way as with impls defined in objects. You specify a bundle name and then select a method from it,
33
+
providing type arguments if necessary.
33
34
34
-
trait BlackboxMacro {
35
-
val c: BlackboxContext
36
-
}
37
-
38
-
trait WhiteboxMacro {
39
-
val c: WhiteboxContext
40
-
}
41
-
42
-
Referencing macro implementations defined in bundles works in the same way as with impls defined in objects. You specify a bundle name
43
-
and then select a method from it, providing type arguments if necessary.
0 commit comments