Skip to content

Commit 35f7f97

Browse files
committed
addressed comments
1 parent f337a8d commit 35f7f97

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ most (but not all) divergence errors in Scala 2 would terminate the implicit sea
122122
def buzz(y: A) = ???
123123
buzz(1) // error: ambiguous
124124
```
125-
**7.** The rule for picking a _most specific_ alternative among a set of overloaded or implicit alternatives is refined to take context parameters into account. All else being equal, an alternative that takes some context parameters is taken to be less specific than an alternative that takes none. If both alternatives take context parameters, we try to choose between them as if they were methods with regular parameters. The following paragraph in the [SLS §
126-
6.26.3](https://scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) is affected by this change:
125+
**7.** The rule for picking a _most specific_ alternative among a set of overloaded or implicit alternatives is refined to take context parameters into account. All else being equal, an alternative that takes some context parameters is taken to be less specific than an alternative that takes none. If both alternatives take context parameters, we try to choose between them as if they were methods with regular parameters. The following paragraph in the [SLS §6.26.3](https://scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) is affected by this change:
127126

128127
_Original version:_
129128

docs/docs/reference/changed-features/overload-resolution.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ g(2)(3)(4) // ok
3333
g(2)(3)("") // ok
3434
```
3535

36-
To make this work, the rules for overloading resolution in [SLS §
37-
6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are augmented
36+
To make this work, the rules for overloading resolution in [SLS §6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are augmented
3837
as follows:
3938

4039
> In a situation where a function is applied to more than one argument list, if overloading
@@ -58,8 +57,7 @@ def f(x: String, f2: String => String) = f2(x)
5857
f("a", _.toUpperCase)
5958
f(2, _ * 2)
6059
```
61-
To make this work, the rules for overloading resolution in [SLS §
62-
6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are modified
60+
To make this work, the rules for overloading resolution in [SLS §6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are modified
6361
as follows:
6462

6563
Replace the sentence

docs/docs/reference/contextual/motivation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following pages introduce a redesign of contextual abstractions in Scala. Th
4949

5050
1. [Given Instances](./givens.md) are a new way to define basic terms that can be synthesized. They replace implicit definitions. The core principle of the proposal is that, rather than mixing the `implicit` modifier with a large number of features, we have a single way to define terms that can be synthesized for types.
5151

52-
2. [`using` Clauses](./using-clauses.md) are a new syntax for implicit _parameters_ and their _arguments_. It unambiguously aligns parameters and arguments, solving a number of language warts. It also allows us to have several `using` clauses in a definition.
52+
2. [Using Clauses](./using-clauses.md) are a new syntax for implicit _parameters_ and their _arguments_. It unambiguously aligns parameters and arguments, solving a number of language warts. It also allows us to have several `using` clauses in a definition.
5353

5454
3. ["Given" Imports](./given-imports.md) are a new class of import selectors that specifically import
5555
givens and nothing else.

docs/docs/reference/metaprogramming/inline.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ pure expressions of constant type.
226226
#### The definition of constant expression
227227
228228
Right-hand sides of inline values and of arguments for inline parameters must be
229-
constant expressions in the sense defined by the [SLS §
230-
6.24](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#constant-expressions),
229+
constant expressions in the sense defined by the [SLS §6.24](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#constant-expressions),
231230
including _platform-specific_ extensions such as constant folding of pure
232231
numeric computations.
233232
@@ -501,8 +500,7 @@ val conjunction: true && true = true
501500
val multiplication: 3 * 5 = 15
502501
```
503502

504-
Many of these singleton operation types are meant to be used infix (as in [SLS §
505-
3.2.10](https://www.scala-lang.org/files/archive/spec/2.13/03-types.html#infix-types)).
503+
Many of these singleton operation types are meant to be used infix (as in [SLS §3.2.10](https://www.scala-lang.org/files/archive/spec/2.13/03-types.html#infix-types)).
506504

507505
Since type aliases have the same precedence rules as their term-level
508506
equivalents, the operations compose with the expected precedence rules:

docs/docs/reference/metaprogramming/macros.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ ${'[T]} = T
7878
The type signatures of quotes and splices can be described using
7979
two fundamental types:
8080

81-
- `Expr[T]`: abstract syntax trees representing expressions of type `T`
82-
- `Type[T]`: type structures representing type `T`.
81+
- `Expr[T]`: abstract syntax trees representing expressions of type `T`
82+
- `Type[T]`: type structures representing type `T`.
8383

8484
Quoting takes expressions of type `T` to expressions of type `Expr[T]`
8585
and it takes types `T` to expressions of type `Type[T]`. Splicing
@@ -103,7 +103,7 @@ operations that will be discussed later on.
103103
A fundamental *phase consistency principle* (PCP) regulates accesses
104104
to free variables in quoted and spliced code:
105105

106-
- _For any free variable reference `x`, the number of quoted scopes and the number of spliced scopes between the reference to `x` and the definition of `x` must be equal_.
106+
- _For any free variable reference `x`, the number of quoted scopes and the number of spliced scopes between the reference to `x` and the definition of `x` must be equal_.
107107

108108
Here, `this`-references count as free variables. On the other
109109
hand, we assume that all imports are fully expanded and that `_root_` is
@@ -129,8 +129,8 @@ situations described above.
129129

130130
In what concerns the range of features it covers, this form of macros introduces
131131
a principled metaprogramming framework that is quite close to the MetaML family of
132-
languages. One difference is that MetaML does not have an equivalent of the PCP
133-
- quoted code in MetaML _can_ access variables in its immediately enclosing
132+
languages. One difference is that MetaML does not have an equivalent of the PCP -
133+
quoted code in MetaML _can_ access variables in its immediately enclosing
134134
environment, with some restrictions and caveats since such accesses involve
135135
serialization. However, this does not constitute a fundamental gain in
136136
expressiveness.
@@ -632,10 +632,9 @@ It is possible to deconstruct or extract values out of `Expr` using pattern matc
632632

633633
`scala.quoted` contains objects that can help extracting values from `Expr`.
634634

635-
* `scala.quoted.Expr`/`scala.quoted.Exprs`: matches an expression of a value (or list of values) and returns the value (or list of values).
636-
* `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Expr`/`Exprs` but only works on primitive values.
637-
* `scala.quoted.Varargs`: matches an explicit sequence of expressions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`.
638-
635+
- `scala.quoted.Expr`/`scala.quoted.Exprs`: matches an expression of a value (or list of values) and returns the value (or list of values).
636+
- `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Expr`/`Exprs` but only works on primitive values.
637+
- `scala.quoted.Varargs`: matches an explicit sequence of expressions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`.
639638

640639
These could be used in the following way to optimize any call to `sum` that has statically known values.
641640
```scala
@@ -646,7 +645,7 @@ private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExp
646645
// argValues is of type Seq[Int]
647646
Expr(argValues.sum) // precompute result of sum
648647
case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]]
649-
val staticSum: Int = argExprs.map(_.value.getOrElse(0))
648+
val staticSum: Int = argExprs.map(_.value.getOrElse(0)).sum
650649
val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.value.isEmpty)
651650
dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg })
652651
case _ =>
@@ -695,7 +694,7 @@ private def sumExpr(args1: Seq[Expr[Int]])(using Quotes): Expr[Int] = {
695694
Sometimes it is necessary to get a more precise type for an expression. This can be achived using the following pattern match.
696695

697696
```scala
698-
def f(exp: Expr[Any])(using Quotes) =
697+
def f(expr: Expr[Any])(using Quotes) =
699698
expr match
700699
case '{ $x: t } =>
701700
// If the pattern match succeeds, then there is some type `t` such that
@@ -713,10 +712,11 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using
713712
argsExpr match {
714713
case Varargs(argExprs) =>
715714
val argShowedExprs = argExprs.map {
716-
case '{ $arg: t } =>
717-
Expr.summon[Show[t]] match {
715+
case '{ $arg: tp } =>
716+
val showTp = Type.of[Show[tp]]
717+
Expr.summon(using showTp) match {
718718
case Some(showExpr) => '{ $showExpr.show($arg) }
719-
case None => report.error(s"could not find implicit for ${showTp.show}", arg); '{???}
719+
case None => report.error(s"could not find implicit for ${Type.show[Show[tp]]}", arg); '{???}
720720
}
721721
}
722722
val newArgsExpr = Varargs(argShowedExprs)
@@ -759,7 +759,7 @@ private def evalExpr(e: Expr[Int])(using Quotes): Expr[Int] = {
759759
e match {
760760
case '{ val y: Int = $x; $body(y): Int } =>
761761
// body: Expr[Int => Int] where the argument represents references to y
762-
evalExpr(Expr.betaReduce(body)(evalExpr(x)))
762+
evalExpr(Expr.betaReduce('{$body(${evalExpr(x)})}))
763763
case '{ ($x: Int) * ($y: Int) } =>
764764
(x.value, y.value) match
765765
case (Some(a), Some(b)) => Expr(a * b)

0 commit comments

Comments
 (0)