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
Grammar and wording changes to 'Basics' page. (#1579)
* Add colon before list
* Change ordered list to unordered list as items do not represent a sequence or hierarchy
* Change 'either' to 'whichever'
* Capitalise first letter of item in a list
* Add 'by' to clarifymeaning
* Add colon before a list
* Add missing word, and add a comma and a 'for' for clarity
* Change html lists to markdown for consistency with other lists
* Change 'set up' verb to 'setup' adjective
* Change 'smoothly' integrates to 'seamlessly' integrates, as 'seamlessly' is more commonly used to express integration.
* Flesh out the word 'that', to provide more clarity
* Change 'behavior' to 'behaviors' for clarity, as it may seem like all objects have one behaviour, instead of each object having its own behaviour
* Change sentence slightly to clarify that subclassing and mixins are two separate options
* Add it for consistency with the rest of the list
* Add missing word
* Capitalise first letter of items in a list
* Change use of 'easy' and 'smoothly' to 'straightforward', as these two words may be an expert's subjective opinion
* Change 'smooth' to 'seamless'
* Change 'close' to 'closely', as 'close' relates to location in physical space. Add 'as reasonably possible' to have a shorter sentence while retaining same meaning.
* Change grammar; should be 'as' instead of 'with'
* Remove reference to contents menu to prevent information overload; there is a link to the next page within the sentence, and again directly below the sentence
* Add a colon directly preceding a list
* Remove unnecessary comma from list item
* Add missing word
* Add a colon before a list
* Change words to increase clarity
* Rearrange wording to increase clarity. Italicise 'ScalaFiddle'
* Italicise 'ScalaFiddle'. Reorganise sentences to group similar information together
* Add a colon when introducing a code example
* Add words for clarity and consistency
* Add more clarity around type inference
* Add more clarity around type inference
* Update description of scala functions.
* Add clarity to anonymous function description
* Change 'parameter' to 'argument'
* Change 'parameter' to 'argument'
* Add parenthesis around 's' to clarify that multiple parameter lists are not a rule
* Remove redundancy of having the word 'colon' followed by the colon punctuation mark
* Clarify the description of 'Unit'
* Flesh out the definition of case classes
* Add missing word
* Add clarity to case class comparison
* Add missing word
* Flesh out the description of traits for clarity
* Clarify the definition of a main method
* Tidy up: add commas and clarifications
* Remove contractions
* Make changes requested in PR comments
Copy file name to clipboardExpand all lines: _tour/basics.md
+43-44Lines changed: 43 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -10,28 +10,25 @@ previous-page: tour-of-scala
10
10
redirect_from: "/tutorials/tour/basics.html"
11
11
---
12
12
13
-
In this page, we will cover basics of Scala.
13
+
In this page, we will cover the basics of Scala.
14
14
15
15
## Trying Scala in the Browser
16
16
17
-
You can run Scala in your browser with ScalaFiddle.
17
+
You can run Scala in your browser with _ScalaFiddle_. This is an easy, zero-setup way to experiment with pieces of Scala code:
18
18
19
19
1. Go to [https://scalafiddle.io](https://scalafiddle.io).
20
20
2. Paste `println("Hello, world!")` in the left pane.
21
-
3.Hit "Run" button. Output appears in the right pane.
21
+
3.Click __Run__. The output appears in the right pane.
22
22
23
-
This is an easy, zero-setup way to experiment with pieces of Scala code.
24
-
25
-
Many of the code examples in this documentation are also integrated with ScalaFiddle, so you
26
-
can directly experiment with them simply by clicking the Run-button.
23
+
_ScalaFiddle_ is integrated with some of the code examples in this documentation; if you see a __Run__ button in a code example below, click it to directly experiment with the code.
27
24
28
25
## Expressions
29
26
30
-
Expressions are computable statements.
27
+
Expressions are computable statements:
31
28
```
32
29
1 + 1
33
30
```
34
-
You can output results of expressions using `println`.
31
+
You can output the results of expressions using `println`:
You can name results of expressions with the `val` keyword.
44
+
You can name the results of expressions using the `val` keyword:
48
45
49
46
```tut
50
47
val x = 1 + 1
@@ -54,13 +51,13 @@ println(x) // 2
54
51
Named results, such as `x` here, are called values. Referencing
55
52
a value does not re-compute it.
56
53
57
-
Values cannot be re-assigned.
54
+
Values cannot be re-assigned:
58
55
59
56
```tut:fail
60
57
x = 3 // This does not compile.
61
58
```
62
59
63
-
Types of values can be inferred, but you can also explicitly state the type, like this:
60
+
The type of a value can be omitted and [inferred](https://docs.scala-lang.org/tour/type-inference.html), or it can be explicitly stated:
64
61
65
62
```tut
66
63
val x: Int = 1 + 1
@@ -78,7 +75,7 @@ x = 3 // This compiles because "x" is declared with the "var" keyword.
78
75
println(x * x) // 9
79
76
```
80
77
81
-
As with values, you can explicitly state the type if you want:
78
+
As with values, the type of a variable can be omitted and [inferred](https://docs.scala-lang.org/tour/type-inference.html), or it can be explicitly stated:
82
79
83
80
```tut
84
81
var x: Int = 1 + 1
@@ -89,7 +86,7 @@ var x: Int = 1 + 1
89
86
90
87
You can combine expressions by surrounding them with `{}`. We call this a block.
91
88
92
-
The result of the last expression in the block is the result of the overall block, too.
89
+
The result of the last expression in the block is the result of the overall block, too:
93
90
94
91
```tut
95
92
println({
@@ -100,17 +97,17 @@ println({
100
97
101
98
## Functions
102
99
103
-
Functions are expressions that take parameters.
100
+
Functions are expressions that have parameters, and take arguments.
104
101
105
-
You can define an anonymous function (i.e. no name) that returns a given integer plus one:
102
+
You can define an anonymous function (i.e., a function that has no name) that returns a given integer plus one:
106
103
107
104
```tut
108
105
(x: Int) => x + 1
109
106
```
110
107
111
108
On the left of `=>` is a list of parameters. On the right is an expression involving the parameters.
112
109
113
-
You can also name functions.
110
+
You can also name functions:
114
111
115
112
{% scalafiddle %}
116
113
```tut
@@ -119,7 +116,7 @@ println(addOne(1)) // 2
119
116
```
120
117
{% endscalafiddle %}
121
118
122
-
Functions may take multiple parameters.
119
+
A function can have multiple parameters:
123
120
124
121
{% scalafiddle %}
125
122
```tut
@@ -128,7 +125,7 @@ println(add(1, 2)) // 3
128
125
```
129
126
{% endscalafiddle %}
130
127
131
-
Or it can take no parameters.
128
+
Or it can have no parameters at all:
132
129
133
130
```tut
134
131
val getTheAnswer = () => 42
@@ -139,7 +136,7 @@ println(getTheAnswer()) // 42
139
136
140
137
Methods look and behave very similar to functions, but there are a few key differences between them.
141
138
142
-
Methods are defined with the `def` keyword. `def` is followed by a name, parameter lists, a return type, and a body.
139
+
Methods are defined with the `def` keyword. `def` is followed by a name, parameter list(s), a return type, and a body:
143
140
144
141
{% scalafiddle %}
145
142
```tut
@@ -148,9 +145,9 @@ println(add(1, 2)) // 3
148
145
```
149
146
{% endscalafiddle %}
150
147
151
-
Notice how the return type is declared _after_ the parameter list and a colon`: Int`.
148
+
Notice how the return type is declared _after_ the parameter list and the`: Int`.
The last expression in the body is the method's return value. (Scala does have a `return` keyword, but it's rarely used.)
180
+
The last expression in the body is the method's return value. (Scala does have a `return` keyword, but it is rarely used.)
184
181
185
182
## Classes
186
183
187
-
You can define classes with the `class` keyword followed by its name and constructor parameters.
184
+
You can define classes with the `class` keyword, followed by its name and constructor parameters:
188
185
189
186
```tut
190
187
class Greeter(prefix: String, suffix: String) {
191
188
def greet(name: String): Unit =
192
189
println(prefix + name + suffix)
193
190
}
194
191
```
195
-
The return type of the method `greet` is `Unit`, which says there's nothing meaningful to return. It's used similarly to `void` in Java and C. (A difference is that because every Scala expression must have some value, there is actually a singleton value of type Unit, written (). It carries no information.)
192
+
The return type of the method `greet` is `Unit`, which signifies that there is nothing meaningful to return. It is used similarly to `void` in Java and C. (A difference is that, because every Scala expression must have some value, there is actually a singleton value of type Unit, written (). It carries no information.)
196
193
197
-
You can make an instance of a class with the `new` keyword.
194
+
You can make an instance of a class with the `new` keyword:
198
195
199
196
```tut
200
197
val greeter = new Greeter("Hello, ", "!")
@@ -205,21 +202,23 @@ We will cover classes in depth [later](classes.html).
205
202
206
203
## Case Classes
207
204
208
-
Scala has a special type of class called a "case" class. By default, case classes are immutable and compared by value. You can define case classes with the `case class` keywords.
205
+
Scala has a special type of class called a "case" class. By default, case classes are immutable, and they are compared by value (unlike classes, which are compared by reference). This makes them additionally useful for [pattern matching](https://docs.scala-lang.org/tour/pattern-matching.html#matching-on-case-classes).
206
+
207
+
You can define case classes with the `case class` keywords:
209
208
210
209
```tut
211
210
case class Point(x: Int, y: Int)
212
211
```
213
212
214
-
You can instantiate case classes without `new` keyword.
213
+
You can instantiate case classes without the `new` keyword:
215
214
216
215
```tut
217
216
val point = Point(1, 2)
218
217
val anotherPoint = Point(1, 2)
219
218
val yetAnotherPoint = Point(2, 2)
220
219
```
221
220
222
-
And they are compared by value.
221
+
Case classes are compared by value, not by reference:
223
222
224
223
```tut
225
224
if (point == anotherPoint) {
@@ -235,13 +234,13 @@ if (point == yetAnotherPoint) {
235
234
} // Point(1,2) and Point(2,2) are different.
236
235
```
237
236
238
-
There is a lot more to case classes that we'd like to introduce, and we are convinced you will fall in love with them! We will cover them in depth [later](case-classes.html).
237
+
There is a lot more to case classes that we would like to introduce, and we are convinced you will fall in love with them! We will cover them in depth [later](case-classes.html).
239
238
240
239
## Objects
241
240
242
241
Objects are single instances of their own definitions. You can think of them as singletons of their own classes.
243
242
244
-
You can define objects with the `object` keyword.
243
+
You can define objects with the `object` keyword:
245
244
246
245
```tut
247
246
object IdFactory {
@@ -253,7 +252,7 @@ object IdFactory {
253
252
}
254
253
```
255
254
256
-
You can access an object by referring to its name.
255
+
You can access an object by referring to its name:
257
256
258
257
```tut
259
258
val newId: Int = IdFactory.create()
@@ -266,17 +265,17 @@ We will cover objects in depth [later](singleton-objects.html).
266
265
267
266
## Traits
268
267
269
-
Traits are types containing certain fields and methods. Multiple traits can be combined.
268
+
Traits are abstract data types containing certain fields and methods. In Scala inheritance, a class can only extend one other class, but it can extend multiple traits.
270
269
271
-
You can define traits with `trait` keyword.
270
+
You can define traits with the `trait` keyword:
272
271
273
272
```tut
274
273
trait Greeter {
275
274
def greet(name: String): Unit
276
275
}
277
276
```
278
277
279
-
Traits can also have default implementations.
278
+
Traits can also have default implementations:
280
279
281
280
{% scalafiddle %}
282
281
```tut
@@ -286,7 +285,7 @@ trait Greeter {
286
285
}
287
286
```
288
287
289
-
You can extend traits with the `extends` keyword and override an implementation with the `override` keyword.
288
+
You can extend traits with the `extends` keyword and override an implementation with the `override` keyword:
290
289
291
290
```tut
292
291
class DefaultGreeter extends Greeter
@@ -305,17 +304,17 @@ customGreeter.greet("Scala developer") // How are you, Scala developer?
305
304
```
306
305
{% endscalafiddle %}
307
306
308
-
Here, `DefaultGreeter` extends only a single trait, but it could extend multiple traits.
307
+
Here, `DefaultGreeter` extends only one single trait, but it could extend multiple traits.
309
308
310
309
We will cover traits in depth [later](traits.html).
311
310
312
311
## Main Method
313
312
314
-
The main method is an entry point of a program. The Java Virtual
315
-
Machine requires a main method to be named `main` and take one
316
-
argument, an array of strings.
313
+
The main method is the entry point of a Scala program. The Java Virtual
314
+
Machine requires a main method, named `main`, that takes one
315
+
argument: an array of strings.
317
316
318
-
Using an object, you can define a main method as follows:
317
+
Using an object, you can define the main method as follows:
Copy file name to clipboardExpand all lines: _tour/tour-of-scala.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Scala is a modern multi-paradigm programming language designed to express common
27
27
Scala is a pure object-oriented language in the sense that [every value is an object](unified-types.html). Types and behaviors of objects are described by [classes](classes.html) and [traits](traits.html). Classes can be extended by subclassing, and by using a flexible [mixin-based composition](mixin-class-composition.html) mechanism as a clean replacement for multiple inheritance.
28
28
29
29
## Scala is functional ##
30
-
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](basics.html#functions) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and it supports [currying](multiple-parameter-lists.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html)model algebraic typesare used in many functional programming languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
30
+
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](basics.html#functions) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and it supports [currying](multiple-parameter-lists.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html)provide the functionality of algebraic types, which are used in many functional languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
31
31
32
32
Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](https://github.com/scala/scala-xml/wiki/XML-Processing) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html), by way of general extension via [extractor objects](extractor-objects.html). In this context, [for comprehensions](for-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services.
0 commit comments