Skip to content

Commit 4be89d8

Browse files
authored
Merge pull request #41 from jetbrains-academy/mikhail/scala-edit
Mikhail/scala edit
2 parents 4a238dc + 2a3a909 commit 4be89d8

File tree

37 files changed

+254
-254
lines changed

37 files changed

+254
-254
lines changed

Classes Vs Case Classes/Case Classes Encoding/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ because it is very common in practice.
1111
So, when we define a case class, the Scala compiler defines a class
1212
enhanced with some more methods and a companion object.
1313

14-
For instance, the following case class definition:
14+
For instance, look at the following case class definition:
1515

1616
case class Note(name: String, duration: String, octave: Int)
1717

18-
Expands to the following class definition:
18+
It expands to the following class definition:
1919

2020
class Note(_name: String, _duration: String, _octave: Int) extends Serializable {
2121

Classes Vs Case Classes/Creation and Manipulation/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
In the previous sections we have seen how case classes could be
3-
used to achieve information aggregation, and also how classes
2+
In the previous sections, we have seen how case classes could be
3+
used to achieve information aggregation and also how classes
44
could be used to achieve data abstraction or to define stateful
55
objects.
66

7-
What are the relationship between classes and case classes? How
7+
What is the relationship between classes and case classes? How
88
do they differ?
99

1010
## Creation and Manipulation

Classes Vs Case Classes/Equality/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ values, whereas the same definitions of notes lead to equal values.
1414

1515
As we have seen in the previous sections, stateful classes introduce a notion of *identity*
1616
that does not exist in case classes. Indeed, the value of `BankAccount` can change over
17-
time whereas the value of a `Note` is immutable.
17+
time, whereas the value of `Note` is immutable.
1818

1919
In Scala, by default, comparing objects will compare their identity, but in the
2020
case of case class instances, the equality is redefined to compare the values of
@@ -38,5 +38,5 @@ implement their equality).
3838

3939
## Exercise
4040

41-
- Complete the creation of two instances of the `BankAccount`.
42-
- Complete the creation of two instances of a `c3` `Note`.
41+
- Complete the creation of two instances of `BankAccount`.
42+
- Complete the creation of two instances of `c3` `Note`.

Definitions and Evaluation/Multiple Parameters/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ Separate several parameters with commas:
77

88
## Parameters and Return Types
99

10-
Function parameters come with their type, which is given after a colon
10+
Function parameters come with their type, which is given after a colon:
1111

1212
def power(x: Double, y: Int): Double = ...
1313

1414
If a return type is given, it follows the parameter list.
1515

1616
## Val vs Def
1717

18-
The right hand side of a `def` definition is evaluated on each use.
18+
The right-hand side of a `def` definition is evaluated on each use.
1919

20-
The right hand side of a `val` definition is evaluated at the point of the definition
20+
The right-hand side of a `val` definition is evaluated at the point of the definition
2121
itself. Afterwards, the name refers to the value.
2222

2323
val x = 2
@@ -27,11 +27,11 @@ For instance, `y` above refers to `4`, not `square(2)`.
2727

2828
## Evaluation of Function Applications
2929

30-
Applications of parametrized functions are evaluated in a similar way as
30+
Applications of parametrized functions are evaluated in a way similar to
3131
operators:
3232

3333
1. Evaluate all function arguments, from left to right.
34-
2. Replace the function application by the function's right-hand side, and, at the same time
34+
2. Replace the function application by the function's right-hand side and, at the same time
3535
3. Replace the formal parameters of the function by the actual arguments.
3636

3737
## Example
@@ -52,7 +52,7 @@ This scheme of expression evaluation is called the *substitution model*.
5252
The idea underlying this model is that all evaluation does is *reduce
5353
an expression to a value*.
5454

55-
It can be applied to all expressions, as long as they have no side effects.
55+
It can be applied to all expressions as long as they have no side effects.
5656

5757
The substitution model is formalized in the λ-calculus, which gives
5858
a foundation for functional programming.
@@ -69,8 +69,8 @@ No. Here is a counter-example:
6969

7070
## Value Definitions and Termination
7171

72-
The difference between `val` and `def` becomes apparent when the right
73-
hand side does not terminate. Given
72+
The difference between `val` and `def` becomes apparent when the right-hand
73+
side does not terminate. Given
7474

7575
def loop: Int = loop
7676

@@ -124,5 +124,5 @@ Scala normally uses call-by-value.
124124
## Exercise
125125

126126
Complete the following definition of the `triangleArea` function,
127-
which takes a triangle base and height as parameters and returns
127+
which takes the base and height of a triangle as parameters and returns
128128
its area.

Definitions and Evaluation/Naming Things/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22
## Naming Things
33

4-
Consider the following program that computes the area of a disc
4+
Consider the following program, which computes the area of a disc
55
whose radius is `10`:
66

77
3.14159 * 10 * 10
88

9-
To make complex expressions more readable we can give meaningful names to
9+
To make complex expressions more readable, we can give meaningful names to
1010
intermediate expressions:
1111

1212
val radius = 10
1313
val pi = 3.14159
1414

1515
pi * radius * radius
1616

17-
Besides making the last expression more readable it also allows us to
17+
Besides making the last expression more readable, it also allows us to
1818
not repeat the actual value of the radius.
1919

2020
## Evaluation
2121

22-
A name is evaluated by replacing it with the right hand side of its definition
22+
A name is evaluated by replacing it with the right-hand side of its definition.
2323

2424
### Example
2525

Functional Loops/Computing the Square Root of a Value/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
## Computing the Square Root of a Value
33

4-
We will define in this section a method
4+
In this section, we will define a square root calculation method:
55

66
/** Calculates the square root of parameter x */
77
def sqrt(x: Double): Double = ...
@@ -38,7 +38,7 @@ Recursive methods need an explicit return type in Scala.
3838

3939
For non-recursive methods, the return type is optional.
4040

41-
Second, we define a method `improve` to improve an estimate and a test to check for termination:
41+
Second, we define a method `improve` to improve the estimate and a test to check for termination:
4242

4343
def improve(guess: Double, x: Double) =
4444
(guess + x / guess) / 2

Functional Loops/Conditional Expressions/task.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11

22
## Conditional Expressions
33

4-
To express choosing between two alternatives, Scala
5-
has a conditional expression `if-else`.
4+
To express the choice between two alternatives, Scala
5+
uses a conditional expression `if-else`.
66

7-
It looks like a `if-else` in Java, but is used for expressions, not statements.
7+
It looks like the `if-else` in Java but is used for expressions, not statements.
88

99
Example:
1010
~~~
1111
def abs(x: Double) = if (x >= 0) x else -x
1212
~~~
13-
`x >= 0` is a *predicate*, of type `Boolean`.
13+
Here `x >= 0` is a *predicate* of type `Boolean`.
1414

1515
## Boolean Expressions
1616

17-
Boolean expressions `b` can be composed of
17+
Boolean expressions `b` can include:
1818

1919
true false // Constants
2020
!b // Negation
2121
b && b // Conjunction
2222
b || b // Disjunction
2323

24-
and of the usual comparison operations:
25-
e <= e, e >= e, e < e, e > e, e == e, e != e
24+
They can also contain the usual comparison operations:
25+
e <= e, e >= e, e < e, e > e, e == e, e != e.
2626

2727
## Rewrite rules for Booleans
2828

@@ -41,11 +41,11 @@ We say these expressions use "short-circuit evaluation".
4141

4242
## Summary
4343

44-
You have seen simple elements of functional programing in Scala.
44+
You have seen simple elements of functional programing in Scala:
4545

46-
- arithmetic and boolean expressions
47-
- conditional expressions if-else
48-
- functions with recursion
46+
- arithmetic and boolean expressions;
47+
- conditional expressions if-else;
48+
- functions with recursion.
4949

5050
You have learned the difference between the call-by-name and
5151
call-by-value evaluation strategies.
@@ -55,4 +55,4 @@ the substitution model.
5555

5656
## Exercise
5757

58-
Complete the following method definition that computes the factorial of a number.
58+
Complete the definition of the following method, which computes the factorial of a number.

Higher Order Functions/Higher Order Functions/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ can be passed as a parameter and returned as a result.
88

99
This provides a flexible way to compose programs.
1010

11-
Functions that take other functions as parameters or that return functions
12-
as results are called *higher order functions*.
11+
Functions that take other functions as parameters or return functions
12+
as a result are called *higher order functions*.
1313

1414
### Motivation
1515

1616
Consider the following programs.
1717

18-
Take the sum of the integers between `a` and `b`:
18+
Taking the sum of the integers between `a` and `b`:
1919

2020
def sumInts(a: Int, b: Int): Int =
2121
if (a > b) 0 else a + sumInts(a + 1, b)
2222

23-
Take the sum of the cubes of all the integers between `a`
23+
Taking the sum of the cubes of all the integers between `a`
2424
and `b`:
2525

2626
def cube(x: Int): Int = x * x * x
2727

2828
def sumCubes(a: Int, b: Int): Int =
2929
if (a > b) 0 else cube(a) + sumCubes(a + 1, b)
3030

31-
Take the sum of the factorials of all the integers between `a`
31+
Taking the sum of the factorials of all the integers between `a`
3232
and `b`:
3333

3434
def sumFactorials(a: Int, b: Int): Int =
@@ -72,22 +72,22 @@ Passing functions as parameters leads to the creation of many small functions.
7272

7373
Sometimes it is tedious to have to define (and name) these functions using `def`.
7474

75-
Compare to strings: We do not need to define a string using `val`. Instead of:
75+
Compare to strings: we do not need to define a string using `val`. Instead of:
7676

7777
val str = "abc"; println(str)
7878

79-
We can directly write:
79+
we can directly write:
8080

8181
println("abc")
8282

83-
because strings exist as *literals*. Analogously we would like function
83+
because strings exist as *literals*. Analogously, we can use function
8484
literals, which let us write a function without giving it a name.
8585

8686
These are called *anonymous functions*.
8787

8888
### Anonymous Function Syntax
8989

90-
Example of a function that raises its argument to a cube:
90+
Example of a function that raises its argument to the third power:
9191

9292
(x: Int) => x * x * x
9393

@@ -108,7 +108,7 @@ can always be expressed using `def` as follows:
108108

109109
{ def f(x1: T1, …, xn: Tn) = e ; f }
110110

111-
where `f` is an arbitrary, fresh name (that's not yet used in the program).
111+
where `f` is an arbitrary, fresh name (that has not yet been used in the program).
112112

113113
One can therefore say that anonymous functions are *syntactic sugar*.
114114

Imperative Programming/Imperative Loops/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
In the first sections, we saw how to write loops using recursion.
55

6-
### While-Loops
6+
### While Loops
77

88
We can also write loops with the `while` keyword:
99

@@ -14,18 +14,18 @@ We can also write loops with the `while` keyword:
1414
r
1515
}
1616

17-
As long as the condition of a *while* statement is `true`,
17+
As long as the condition of the `while` statement is `true`,
1818
its body is evaluated.
1919

20-
### For-Loops
20+
### For Loops
2121

22-
In Scala there is a kind of `for` loop:
22+
In Scala, there is a kind of `for` loop, too:
2323

2424
for (i <- 1 until 3) { System.out.print(i.toString + " ") }
2525

2626
This displays `1 2`.
2727

28-
For-loops translate similarly to for-expressions, but using the
28+
`For` loops translate similarly to `for` expressions but use the
2929
`foreach` combinator instead of `map` and `flatMap`.
3030

3131
`foreach` is defined on collections with elements of type `A` as follows:
@@ -37,7 +37,7 @@ Example:
3737

3838
for (i <- 1 until 3; j <- "abc") println(s"$i $j")
3939

40-
translates to:
40+
It translates to:
4141

4242
(1 until 3) foreach (i => "abc" foreach (j => println(s"$i $j")))
4343

0 commit comments

Comments
 (0)