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
In Scala 2 there is no straightforward way to represent a single quote character `"` in a single quoted interpolation. A `\` character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the `"` should be escaped or used as a terminator.
7
+
In Scala 2 there is no straightforward way to represent a single quote character `"` in a single quoted interpolation. A `\` character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the `"`character should be escaped or used as a terminator.
8
8
9
9
In Scala 3, we can use the `$` meta character of interpolations to escape a `"` character. Example:
Scala 3 offers a new way to define programs that can be invoked from the command line:
8
-
A `@main` annotation on a method turns this method into an executable program.
8
+
A [`@main`](https://scala-lang.org/api/3.x/scala/main.html) annotation on a method turns this method into an executable program.
9
9
Example:
10
10
11
11
```scala
@@ -31,13 +31,11 @@ This would generate a main program `happyBirthday` that could be called like thi
31
31
Happy 23rd birthday, Lisa and Peter
32
32
```
33
33
34
-
A `@main` annotated method can be written either at the top-level or in a statically accessible object. The name of the program is in each case the name of the method, without any object prefixes. The `@main` method can have an arbitrary number of parameters.
35
-
For each parameter type there must be an instance of the `scala.util.CommandLineParser.FromString` type class
36
-
that is used to convert an argument string to the required parameter type.
37
-
The parameter list of a main method can end in a repeated parameter that then
38
-
takes all remaining arguments given on the command line.
34
+
A [`@main`](https://scala-lang.org/api/3.x/scala/main.html) annotated method can be written either at the top-level or in a statically accessible object. The name of the program is in each case the name of the method, without any object prefixes. The [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method can have an arbitrary number of parameters.
35
+
For each parameter type there must be an instance of the [`scala.util.CommandLineParser.FromString[T]`](https://scala-lang.org/api/3.x/scala/util/CommandLineParser$$FromString.html) type class that is used to convert an argument string to the required parameter type `T`.
36
+
The parameter list of a main method can end in a repeated parameter that then takes all remaining arguments given on the command line.
39
37
40
-
The program implemented from a `@main` method checks that there are enough arguments on
38
+
The program implemented from a [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method checks that there are enough arguments on
41
39
the command line to fill in all parameters, and that argument strings are convertible to
42
40
the required types. If a check fails, the program is terminated with an error message.
43
41
@@ -51,11 +49,11 @@ Illegal command line after first argument: more arguments expected
51
49
Illegal command line: java.lang.NumberFormatException: For input string: "sixty"
52
50
```
53
51
54
-
The Scala compiler generates a program from a `@main` method `f` as follows:
52
+
The Scala compiler generates a program from a [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method `f` as follows:
55
53
56
-
- It creates a class named `f` in the package where the `@main` method was found
54
+
- It creates a class named `f` in the package where the [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method was found
57
55
- The class has a static method `main` with the usual signature. It takes an `Array[String]`
58
-
as argument and returns `Unit`.
56
+
as argument and returns [`Unit`](https://scala-lang.org/api/3.x/scala/Unit.html).
59
57
- The generated `main` method calls method `f` with arguments converted using
60
58
methods in the [`scala.util.CommandLineParser`](https://scala-lang.org/api/3.x/scala/util/CommandLineParser$.html) object.
61
59
@@ -77,13 +75,13 @@ final class happyBirthday:
77
75
**Note**: The `<static>` modifier above expresses that the `main` method is generated
78
76
as a static method of class `happyBirthDay`. It is not available for user programs in Scala. Regular "static" members are generated in Scala using objects instead.
79
77
80
-
`@main` methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3. They replace the previous scheme to write program as objects with a special `App` parent class. In Scala 2, `happyBirthday` could be written also like this:
78
+
[`@main`](https://scala-lang.org/api/3.x/scala/main.html) methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3. They replace the previous scheme to write program as objects with a special `App` parent class. In Scala 2, `happyBirthday` could be written also like this:
81
79
82
80
```scala
83
81
objecthappyBirthdayextendsApp:
84
82
// needs by-hand parsing of arguments vector
85
83
...
86
84
```
87
85
88
-
The previous functionality of `App`, which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://scala-lang.org/api/3.x/scala/App.md) still exists in limited form for now, but it does not support command line arguments and will be deprecated in the future. If programs need to cross-build
86
+
The previous functionality of [`App`](https://www.scala-lang.org/api/3.x/scala/App.html), which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://scala-lang.org/api/3.x/scala/App.html) still exists in limited form for now, but it does not support command line arguments and will be deprecated in the future. If programs need to cross-build
89
87
between Scala 2 and Scala 3, it is recommended to use an explicit `main` method with an `Array[String]` argument instead.
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/pattern-bindings.md
+2-3
Original file line number
Diff line number
Diff line change
@@ -21,12 +21,11 @@ This code gives a compile-time warning in Scala 3.1 (and also in Scala 3.0 under
21
21
valpair= (1, true)
22
22
val (x, y) = pair
23
23
```
24
-
Sometimes one wants to decompose data anyway, even though the pattern is refutable. For instance, if at some point one knows that a list `elems` is non-empty one might
25
-
want to decompose it like this:
24
+
Sometimes one wants to decompose data anyway, even though the pattern is refutable. For instance, if at some point one knows that a list `elems` is non-empty one might want to decompose it like this:
26
25
```scala
27
26
valfirst:: rest = elems // error
28
27
```
29
-
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a warning. One can avoid the warning by marking the right-hand side with an `@unchecked` annotation:
28
+
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a warning. One can avoid the warning by marking the right-hand side with an [`@unchecked`](https://scala-lang.org/api/3.x/scala/unchecked.html) annotation:
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/structural-types.md
+9-10
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ help from the user. In practice, the connection between a structural type
59
59
and its underlying generic representation would most likely be done by
60
60
a database layer, and therefore would not be a concern of the end user.
61
61
62
-
`Record` extends the marker trait `scala.Selectable` and defines
62
+
`Record` extends the marker trait [`scala.Selectable`](https://scala-lang.org/api/3.x/scala/Selectable.html) and defines
63
63
a method `selectDynamic`, which maps a field name to its value.
64
64
Selecting a structural type member is done by calling this method.
65
65
The `person.name` and `person.age` selections are translated by
@@ -90,7 +90,7 @@ Structural types can also be accessed using [Java reflection](https://www.oracle
90
90
defclose():Unit
91
91
```
92
92
93
-
Here, we define a structural type `Closeable` that defines a `close` method. There are various classes that have `close` methods, we just list `FileInputStream` and `Channel` as two examples. It would be easiest if the two classes shared a common interface that factors out the `close` method. But such factorings are often not possible if different libraries are combined in one application. Yet, we can still have methods that work on
93
+
Here, we define a structural type `Closeable` that defines a `close` method. There are various classes that have `close` methods, we just list [`FileInputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/FileInputStream.html#%3Cinit%3E(java.io.File)) and [`Channel`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/channels/Channel.html) as two examples. It would be easiest if the two classes shared a common interface that factors out the `close` method. But such factorings are often not possible if different libraries are combined in one application. Yet, we can still have methods that work on
94
94
all classes with a `close` method by using the `Closeable` type. For instance,
95
95
96
96
```scala
@@ -147,10 +147,9 @@ i3.range
147
147
148
148
The type of `i3` in this example is `Vehicle { val range: Int }`. Hence,
149
149
`i3.range` is well-formed. Since the base class `Vehicle` does not define a `range` field or method, we need structural dispatch to access the `range` field of the anonymous class that initializes `id3`. Structural dispatch
150
-
is implemented by the base trait `reflect.Selectable` of `Vehicle`, which
151
-
defines the necessary `selectDynamic` member.
150
+
is implemented by the base trait [`reflect.Selectable`](https://scala-lang.org/api/3.x/scala/reflect/Selectable.html) of `Vehicle`, which defines the necessary `selectDynamic` member.
152
151
153
-
`Vehicle` could also extend some other subclass of `scala.Selectable` that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck:
152
+
`Vehicle` could also extend some other subclass of [`scala.Selectable`](https://scala-lang.org/api/3.x/scala/Selectable.html) that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck:
154
153
155
154
```scala
156
155
traitVehicle:
@@ -168,25 +167,25 @@ adding any refinements. Hence, `i3` now has just type `Vehicle` and the selectio
168
167
169
168
Note that in Scala 2 all local and anonymous classes could produce values with refined types. But
170
169
members defined by such refinements could be selected only with the language import
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/givens.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -120,9 +120,9 @@ In each case, a pattern-bound given instance consists of `given` and a type `T`.
120
120
121
121
Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement the analogue of a "negated" search in implicit resolution,
122
122
where a query Q1 fails if some other query Q2 succeeds and Q1 succeeds if Q2 fails. With the new cleaned up behavior these techniques no longer work.
123
-
But the new special type `scala.util.NotGiven` now implements negation directly.
123
+
But the new special type [`scala.util.NotGiven`](https://scala-lang.org/api/3.x/scala/util/NotGiven.html) now implements negation directly.
124
124
125
-
For any query type `Q`, `NotGiven[Q]` succeeds if and only if the implicit
125
+
For any query type `Q`, [`NotGiven[Q]`](https://scala-lang.org/api/3.x/scala/util/NotGiven.html) succeeds if and only if the implicit
literal translation of the symbol literal `'xyz` is `Symbol("xyz")`. However, it is recommended to use a plain string literal `"xyz"` instead. (The `Symbol` class will be deprecated and removed in the future).
9
+
The [`scala.Symbol`](https://scala-lang.org/api/3.x/scala/Symbol.html) class still exists, so a literal translation of the symbol literal `'xyz` is `Symbol("xyz")`. However, it is recommended to use a plain string literal `"xyz"` instead. (The `Symbol` class will be deprecated and removed in the future). Example:
0 commit comments