Skip to content

Commit d32d26d

Browse files
committed
Merge branch 'master' of github.com:scala/scala.github.com
2 parents 065883f + 3d7cf5b commit d32d26d

File tree

15 files changed

+146
-145
lines changed

15 files changed

+146
-145
lines changed

overviews/quasiquotes/definition-details.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

13-
## Modifiers {:#modifiers}
13+
## Modifiers
1414

1515
Every definition except packages and package objects have associtated modifiers object which contains following data:
1616

@@ -62,7 +62,7 @@ Considering the fact that definitions might contain various low-level flags adde
6262

6363
scala> val q"$_ def f" = q"@foo @bar implicit def f"
6464

65-
## Templates {:#templates}
65+
## Templates
6666

6767
Templates are a common abstraction in definition trees that is used in new expressions, classes, traits, objects, package objects. Although there is no interpolator for it at the moment we can illustrate its structure on the example of new expression (similar handling will applly to all other template-bearing trees):
6868

@@ -111,9 +111,9 @@ So template consists of:
111111
scala> val q"new { ..$body }" = q"new { val x = 1; def y = 'y }"
112112
body: List[universe.Tree] = List(val x = 1, def y = scala.Symbol("y"))
113113

114-
## Val and Var Definitions {:#val-var}
114+
## Val and Var Definitions
115115

116-
Vals and vars allow you to define immutable and mutable variables correspondingly. Additionally they are also used to represent [function](/overviews/quasiquotes/expression-details.html#function), [class](#class) and [method](#method) paremeters.
116+
Vals and vars allow you to define immutable and mutable variables correspondingly. Additionally they are also used to represent [function](/overviews/quasiquotes/expression-details.html#function), [class](#class-definition) and [method](#method-definition) paremeters.
117117

118118
Each val and var consistents of four components: modifiers, name, type tree and a right hand side:
119119

@@ -126,7 +126,7 @@ Each val and var consistents of four components: modifiers, name, type tree and
126126
tpt: universe.Tree = <type ?>
127127
rhs: universe.Tree = 2
128128

129-
If type of the val isn't explicitly specified by the user an [empty type](/overviews/quasiquotes/type-details.html#empty) is used as tpt.
129+
If type of the val isn't explicitly specified by the user an [empty type](/overviews/quasiquotes/type-details.html#empty-type) is used as tpt.
130130

131131
Vals and vars are disjoint (they don't match one another):
132132

@@ -142,7 +142,7 @@ Vars always have `MUTABLE` flag in their modifiers:
142142
tpt: universe.Tree = <type ?>
143143
rhs: universe.Tree = 2
144144

145-
## Pattern Definitions {:#pattern}
145+
## Pattern Definitions
146146

147147
Pattern definitions allow to use scala pattern matching capabilities to define variables. Unlike
148148
val and var definitions, pattern definitions are not first-class and they are get represented
@@ -202,7 +202,7 @@ Simiarly one can also construct a mutable pattern definition:
202202

203203
q"$mods var $pat: $tpt = $rhs"
204204

205-
## Type Definition {:#type}
205+
## Type Definition
206206

207207
Type definition have two possible shapes: abstract type definitions and alias type definitions.
208208

@@ -237,7 +237,7 @@ Due to low level uniform representation of type aliases and abstract types one m
237237

238238
Where `tpt` has a `TypeBoundsTree(low, high)` shape.
239239

240-
## Method Definition {:#method}
240+
## Method Definition
241241

242242
Each method consists of modifiers, name, type arguments, value arguments, return type and a body:
243243

@@ -249,7 +249,7 @@ Each method consists of modifiers, name, type arguments, value arguments, return
249249
tpt: universe.Tree = <type ?>
250250
body: universe.Tree = 1
251251

252-
Type arguments are [type definitions](#type) and value arguments are [val definitions](#val-var). Inferred return type is represented as [empty type](/overviews/quasiquotes/type-details.html#empty). If body of the method is [empty expression](/overviews/quasiquotes/expression-details.html#empty) it means that method is abstract.
252+
Type arguments are [type definitions](#type-definition) and value arguments are [val definitions](#val-and-var-definitions). Inferred return type is represented as [empty type](/overviews/quasiquotes/type-details.html#empty-type). If body of the method is [empty expression](/overviews/quasiquotes/expression-details.html#empty) it means that method is abstract.
253253

254254
Alternatively you can also deconstruct arguments separating implicit and non-implicit parameters:
255255

@@ -267,7 +267,7 @@ This way of parameter handling will still work if method doesn\'t have any impli
267267
implparams: List[universe.ValDef] = List()
268268
body: universe.Tree = x.$plus(y)
269269

270-
## Secondary Constructor Definition {:#ctor}
270+
## Secondary Constructor Definition
271271

272272
Secondary constructors are special kinds of methods that have following shape:
273273

@@ -288,19 +288,19 @@ Due to low level underlying representation of trees secondary constructors are r
288288
tpt: universe.Tree = <type ?>
289289
body: universe.Tree = <init>(0)
290290

291-
## Class Definition {:#class}
291+
## Class Definition
292292

293293
Classes have a following structure:
294294

295295
q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
296296

297297
As you probably already see the right part after extends is just a [template](#templates). Apart from it and modifiers classes
298298
also have primary constructor which consists of constructor modifiers, type and value parameters which behave very much like
299-
[method](#method) modifiers and parameters.
299+
[method](#method-definition) modifiers and parameters.
300300

301-
## Trait Definition {:#trait}
301+
## Trait Definition
302302

303-
Syntactically traits are quite similar to [classes](#class) sans value parameters and constructor modifiers:
303+
Syntactically traits are quite similar to [classes](#class-definition) sans value parameters and constructor modifiers:
304304

305305
q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
306306

@@ -316,13 +316,13 @@ A workaround it to always extract modifiers with wildcard pattern:
316316
name: universe.TypeName = X
317317
stats: List[universe.Tree] = List(def x: Int)
318318

319-
## Object Definition {:#object}
319+
## Object Definition
320320

321-
Syntactically objects are quite similar [classes](#class) without constructors:
321+
Syntactically objects are quite similar [classes](#class-definition) without constructors:
322322

323323
q"$mods object $tname extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
324324

325-
## Package Definition {:#package}
325+
## Package Definition
326326

327327
Packages are a fundamental primitive to organize source code. You can express them in quasiquotes as:
328328

@@ -350,7 +350,7 @@ Packages are a fundamental primitive to organize source code. You can express th
350350
Quasiquotes don\'t support inline package definition syntax that are usually used in the
351351
header of the source file (but it's equivalent to the supported one in terms of ASTs).
352352

353-
## Package Object Definition{:#package-object}
353+
## Package Object Definition
354354

355355
Package objects are a cross between packages and object:
356356

overviews/quasiquotes/expression-details.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

13-
## Empty {:#empty}
13+
## Empty
1414

1515
`q""` is used to indicate that some part of the tree is not provided by the user:
1616

@@ -21,7 +21,7 @@ outof: 13
2121

2222
Default toString formats `q""` as `<empty>`.
2323

24-
## Literal {:#literal}
24+
## Literal
2525

2626
Scala has a number of default built-in literals:
2727

@@ -45,7 +45,7 @@ Thanks to [lifting](/overviews/quasiquotes/lifting.html) you can also easily cre
4545
scala> val one = q"$x"
4646
one: universe.Tree = 1
4747

48-
This would work the same way for all literal types (see [standard liftables](/overviews/quasiquotes/lifting.html#standard) except `Null`. Lifting of `null` value and `Null` type isn't supported, use `q"null"` if you really mean to create null literal:
48+
This would work the same way for all literal types (see [standard liftables](/overviews/quasiquotes/lifting.html#standard-liftables) except `Null`. Lifting of `null` value and `Null` type isn't supported, use `q"null"` if you really mean to create null literal:
4949

5050
scala> val x = null
5151
scala> q"$x"
@@ -58,9 +58,9 @@ During deconstruction you can use [unlifting](/overviews/quasiquotes/unlifting.h
5858
scala> val q"${x: Int}" = q"1"
5959
x: Int = 1
6060

61-
Similarly it would work with all the literal types except `Null`. (see [standard unliftables](/overviews/quasiquotes/unlifting.html#standard))
61+
Similarly it would work with all the literal types except `Null`. (see [standard unliftables](/overviews/quasiquotes/unlifting.html#standard-unliftables))
6262

63-
## Identifier and Selection {:#ref}
63+
## Identifier and Selection
6464

6565
Identifiers and member selections are two fundamental primitives that let you refer to other definitions. Combination of two of them is also known `RefTree`.
6666

@@ -98,7 +98,7 @@ Similarly you can create and extract member selections:
9898
scala> val q"foo.$name" = selected
9999
name: universe.TermName = bar
100100

101-
## Super and This {:#super-this}
101+
## Super and This
102102

103103
One can use this and super to select precise members within inheritance chain.
104104

@@ -129,7 +129,7 @@ Similarly for super we have:
129129
qual: universe.TypeName = T
130130
field: universe.Name = foo
131131

132-
## Application and Type Application {:#application}
132+
## Application and Type Application
133133

134134
Value applications and type applications are two fundamental parts out of which one can construct calls to Scala functions and methods. Lets assume that we would like to handle function calls to the following method:
135135

@@ -187,7 +187,7 @@ Similarly to type arguments, implicit value arguments are automatically inferred
187187
stats: List[universe.Tree] = List(def g(x: Int)(implicit y: Int): Int = x.+(y), implicit val y: Int = 3)
188188
argss: List[List[universe.Tree]] = List(List(2), List(y))
189189

190-
## Assign and Update {:#assign-update}
190+
## Assign and Update
191191

192192
Assign and update are two related ways to explictly mutate a variable or collection:
193193

@@ -222,7 +222,7 @@ On the other hand if you want to treat this two cases separately it's also possi
222222
update array at List(0) with 1
223223

224224

225-
## Return {:#return}
225+
## Return
226226

227227
Return expressions is used to perform early return from a function.
228228

@@ -232,7 +232,7 @@ Return expressions is used to perform early return from a function.
232232
scala> val q"return $expr" = ret
233233
expr: universe.Tree = 2.$plus(2)
234234

235-
## Throw {:#throw}
235+
## Throw
236236

237237
Throw expression is used to throw a throwable:
238238

@@ -242,7 +242,7 @@ Throw expression is used to throw a throwable:
242242
scala> val q"throw $expr" = thr
243243
expr: universe.Tree = new Exception()
244244

245-
## Ascription {:#ascription}
245+
## Ascription
246246

247247
Ascriptions lets users to annotate type of intermidiate expression:
248248

@@ -253,7 +253,7 @@ Ascriptions lets users to annotate type of intermidiate expression:
253253
expr: universe.Tree = 1.$plus(1)
254254
tpt: universe.Tree = Int
255255

256-
## Annotation {:#annotated}
256+
## Annotation
257257

258258
Expressions can be annotated:
259259

@@ -270,9 +270,9 @@ It's important to mention that such pattern won't match if we combine annotation
270270
scala.MatchError: (1.$plus(1): Int @positive) (of class scala.reflect.internal.Trees$Typed)
271271
... 32 elided
272272

273-
In this case we need to deconstruct it as [ascription](#ascription) and then deconstruct `tpt` as [annotated type](/overviews/quasiquotes/type-details.html#annotated).
273+
In this case we need to deconstruct it as [ascription](#ascription) and then deconstruct `tpt` as [annotated type](/overviews/quasiquotes/type-details.html#annotated-type).
274274

275-
## Tuple {:#tuple}
275+
## Tuple
276276

277277
Tuples are heteregeneous data structures with built-in user-friendly syntax. The syntax itself is just a sugar that maps onto `scala.TupleN` calls:
278278

@@ -313,7 +313,7 @@ And unit as nullary tuple:
313313
scala> val q"(..$elems)" = q"()"
314314
elems: List[universe.Tree] = List()
315315

316-
## Block {:#block}
316+
## Block
317317

318318
Blocks are a fundamental primitive to express sequence of actions or bindings. `q"..."` interpolator is an equivalent of a block. It allows to express more than one expression seperated by semicolon or a newline:
319319

@@ -383,9 +383,9 @@ Zero-element block is equivalent to synthetic unit (one that was inserted by the
383383
scala> val syntheticUnit = q"..$stats"
384384
syntheticUnit: universe.Tree = ()
385385

386-
Such units are used in empty else branches of [ifs](#if) and empty bodies of [case clauses](#match) making it convenient to work with those cases as with zero-element blocks.
386+
Such units are used in empty else branches of [ifs](#if) and empty bodies of [case clauses](#pattern-match) making it convenient to work with those cases as with zero-element blocks.
387387

388-
## If {:#if}
388+
## If
389389

390390
There are two varieties of if expressions: those with else clause and without it:
391391

@@ -401,7 +401,7 @@ There are two varieties of if expressions: those with else clause and without it
401401

402402
No-else clause is equivalent to else clause that contains a synthetic unit literal ([empty block](#block)).
403403

404-
## Pattern Match {:#match}
404+
## Pattern Match
405405

406406
Pattern matching is cornerstone feature of Scala that lets you deconstruct values into their components:
407407

@@ -433,7 +433,7 @@ Case clause without body is equivalent to one holding synthetic unit literal ([e
433433

434434
No-guard is represented with the help of [empty expression](#empty).
435435

436-
## Try {:#try}
436+
## Try
437437

438438
Try expression is used to handle possible error conditions and ensure consistent state via finally. Both error handling cases and finally clause are optional.
439439

@@ -454,9 +454,9 @@ Try expression is used to handle possible error conditions and ensure consistent
454454
b: List[universe.CaseDef] = List()
455455
c: universe.Tree = f
456456

457-
Similarly to [pattern matching](#match) cases can be further deconstructed with `cq"..."`. No-finally clause is represented with the help of [empty expression](#empty).
457+
Similarly to [pattern matching](#pattern-match) cases can be further deconstructed with `cq"..."`. No-finally clause is represented with the help of [empty expression](#empty).
458458

459-
## Function {:#function}
459+
## Function
460460

461461
There are three ways to create anonymous function:
462462

@@ -474,8 +474,8 @@ on type inference to infer its type. Last one explicitly defines function parame
474474
to implementation restriction second notation can only be used in parenthesis or inside other
475475
expression. If you leave them out you have to specify parameter types.
476476

477-
Parameters are represented as [Vals](/overviews/quasiquotes/definition-details.html#val-var). If you want to programmatically create val that should have
478-
its type inferred you need to use [empty type](/overviews/quasiquotes/type-details.html#empty):
477+
Parameters are represented as [Vals](/overviews/quasiquotes/definition-details.html#val-and-var-definitions). If you want to programmatically create val that should have
478+
its type inferred you need to use [empty type](/overviews/quasiquotes/type-details.html#empty-type):
479479

480480
scala> val tpt = tq""
481481
tpt: universe.TypeTree = <type ?>
@@ -508,7 +508,7 @@ You can also tear arguments further apart:
508508
It's recommended to use underscore pattern in place of [modifiers](/overviews/quasiquotes/definition-details.html#modifiers) even if you don't plan to work
509509
with them as parameters may contains additional flags which might cause match errors.
510510

511-
## Partial Function {:#partial-function}
511+
## Partial Function
512512

513513
Partial functions are a neat syntax that lets you express functions with
514514
limited domain with the help of pattern matching:
@@ -528,7 +528,7 @@ trees for match expressions. Despite this fact they do not match one another:
528528
scala> val q"$expr match { case ..$cases }" = pf
529529
scala.MatchError: ...
530530

531-
## While and Do-While Loops {:#while}
531+
## While and Do-While Loops
532532

533533
While and do-while loops are low-level control structures that used when performance of iteration
534534
is critical:
@@ -563,7 +563,7 @@ is critical:
563563
body: universe.Tree = x.$minus$eq(1)
564564
cond: universe.Tree = x.$greater(0)
565565

566-
## For and For-Yield Loops {:#for}
566+
## For and For-Yield Loops
567567

568568
For and For-Yield expressions allow to write monadic style comprehensions that desugar into calls to `map`, `flatMap`, `foreach` and `withFilter` methods:
569569

@@ -595,7 +595,7 @@ It's important to mention that For and For-Yield do not cross-match each other:
595595
scala> val q"for (..$enums) $body" = `for-yield`
596596
scala.MatchError: ...
597597

598-
## New {:#new}
598+
## New
599599

600600
New expression lets you construct an instance of given type possibly refining it with other types or definitions:
601601

@@ -605,7 +605,7 @@ New expression lets you construct an instance of given type possibly refining it
605605

606606
See [templates](/overviews/quasiquotes/definition-details.html#templates) section for details.
607607

608-
## Import {:#import}
608+
## Import
609609

610610
Import trees consist of reference and a list of selectors:
611611

overviews/quasiquotes/future.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

13-
In [Project Palladium](www.scalareflect.org) we are working on the following features that target future versions of Scala:
13+
In the [scala.meta](http://scalameta.org) project we are working on the following features that target future versions of Scala:
1414

1515
* Hygiene: [SI-7823](https://issues.scala-lang.org/browse/SI-7823)
1616
* Alternative to Scheme's ellipsis: [SI-8164](https://issues.scala-lang.org/browse/SI-8164)

overviews/quasiquotes/hygiene.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Sophisticated macro systems such as Racket's have mechanisms that make macros hy
1616

1717
Preventing name clashes between regular and generated code means two things. First, we must ensure that regardless of the context in which we put generated code, its meaning isn't going to change (*referential transparency*). Second, we must make certain that regardless of the context in which we splice regular code, its meaning isn't going to change (often called *hygiene in the narrow sense*). Let's see what can be done to this end on a series of examples.
1818

19-
## Referential transparency {:#referential-transparency}
19+
## Referential transparency
2020

2121
What referential transparency means is that quasiquotes should remember the lexical context in which they are defined. For instance, if there are imports provided at the definition site of the quasiquote, then these imports should be used to resolve names in the quasiquote. Unfortunately, this is not the case at the moment, and here's an example:
2222

@@ -86,7 +86,7 @@ And wrapper will be resolved to `example.Test.wrapper` rather than intended `exa
8686
q"$wrapper($x)"
8787
}
8888

89-
## Hygiene in the narrow sense {:#hygiene-in-the-narrow-sense}
89+
## Hygiene in the narrow sense
9090

9191
What hygiene in the narrow sense means is that quasiquotes shouldn't mess with the bindings of trees that are unquoted into them. For example, if a macro argument unquoted into a macro expansion was originally referring to some variable in enclosing lexical context, then this reference should remain in force after macro expansion, regardless of what code was generated for the macro expansion. Unfortunately, we don't have automatic facilities to ensure this, and that can lead to unexpected situations:
9292

0 commit comments

Comments
 (0)