SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 30 day free trial to unlock unlimited reading.
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
19.
I
• Takes several parameter lists
First comes a single
parameter, of type
Context
20.
I
• Takes several parameter lists
Macro definition
Next, followed by a list of
parameters that have the
same names as the macro
definition parameters
21.
I
• The original macro parameter has
• type T
• A macro implementation parameter has
• type c.Expr[T]
22.
Q
• q"..." string interpolators that build code
• Unnecessary to directly implement the AST
• To use the quasiquotes from the macro, just write
import c.universe._
23.
Q
• Using the showRaw, it is possible to see the AST
24.
Goodness
• The hard to comprehend notion of meta
programming
• def macros are similar to the concept of a typed
method call
47.
Current state
• Optimized towards compiler developers, not library
users
Complicated
48.
Scala 2.12 (plan)
• Not introduce new features
• Bugfixes and stability improvements
• Mention later why reason
49.
scala.meta
• A new experimental API for metaprogramming
• F
50.
scala.meta
• Implemented in a library shipped separately from
the official Scala distribution
• The first milestone release is scheduled for this fall
51.
The goal of scala.meta
• Metaprogramming easy
• New API is going to greatly simplify writing
macros
• Not require knowledge of compiler internals
52.
Language model
• All represented with trees
Types
Modifiers
…
Names
Trees
scala.meta
Terms
Symbols
53.
Language model
• Keeps all the information about the program
• Comments also remain
• No information is lost anymore
54.
Manner of utilization
• Code generation
• Static type checking
• etc…
55.
Summary
• Macros are actively used in the OSS library
• Can be more efficiently and safely programming
• Scala macros are evolving