1717package scalatutorial .sections
1818
1919/**
20- * @param name definitions_and_evaluation
20+ * @param name
21+ * definitions_and_evaluation
2122 */
2223object DefinitionsAndEvaluation extends ScalaTutorialSection {
2324
2425 /**
25- * = Naming Things =
26+ * =Naming Things=
2627 *
27- * Consider the following program that computes the area of a disc
28- * whose radius is `10`:
28+ * Consider the following program that computes the area of a disc whose radius is `10`:
2929 *
3030 * {{{
3131 * 3.14159 * 10 * 10
3232 * }}}
3333 *
34- * To make complex expressions more readable we can give meaningful names to
35- * intermediate expressions:
34+ * To make complex expressions more readable we can give meaningful names to intermediate
35+ * expressions:
3636 *
3737 * {{{
3838 * val radius = 10
@@ -41,14 +41,14 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
4141 * pi * radius * radius
4242 * }}}
4343 *
44- * Besides making the last expression more readable it also allows us to
45- * not repeat the actual value of the radius.
44+ * Besides making the last expression more readable it also allows us to not repeat the actual
45+ * value of the radius.
4646 *
47- * = Evaluation =
47+ * =Evaluation=
4848 *
4949 * A name is evaluated by replacing it with the right hand side of its definition
5050 *
51- * == Example ==
51+ * ==Example==
5252 *
5353 * Here are the evaluation steps of the above expression:
5454 *
@@ -61,7 +61,7 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
6161 * 314.159
6262 * }}}
6363 *
64- * = Methods =
64+ * =Methods=
6565 *
6666 * Definitions can have parameters. For instance:
6767 */
@@ -83,15 +83,15 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
8383 }
8484
8585 /**
86- * = Multiple Parameters =
86+ * =Multiple Parameters=
8787 *
8888 * Separate several parameters with commas:
8989 *
9090 * {{{
9191 * def sumOfSquares(x: Double, y: Double) = square(x) + square(y)
9292 * }}}
9393 *
94- * = Parameters and Return Types =
94+ * =Parameters and Return Types=
9595 *
9696 * Function parameters come with their type, which is given after a colon
9797 *
@@ -101,12 +101,12 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
101101 *
102102 * If a return type is given, it follows the parameter list.
103103 *
104- * = Val vs Def =
104+ * =Val vs Def=
105105 *
106106 * The right hand side of a `def` definition is evaluated on each use.
107107 *
108- * The right hand side of a `val` definition is evaluated at the point of the definition
109- * itself. Afterwards, the name refers to the value.
108+ * The right hand side of a `val` definition is evaluated at the point of the definition itself.
109+ * Afterwards, the name refers to the value.
110110 *
111111 * {{{
112112 * val x = 2
@@ -115,16 +115,15 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
115115 *
116116 * For instance, `y` above refers to `4`, not `square(2)`.
117117 *
118- * = Evaluation of Function Applications =
118+ * =Evaluation of Function Applications=
119119 *
120- * Applications of parametrized functions are evaluated in a similar way as
121- * operators:
120+ * Applications of parametrized functions are evaluated in a similar way as operators:
122121 *
123- * 1. Evaluate all function arguments, from left to right
124- * 1. Replace the function application by the function's right-hand side, and, at the same time
125- * 1. Replace the formal parameters of the function by the actual arguments.
122+ * 1. Evaluate all function arguments, from left to right
123+ * 1. Replace the function application by the function's right-hand side, and, at the same time
124+ * 1. Replace the formal parameters of the function by the actual arguments.
126125 *
127- * == Example ==
126+ * ==Example==
128127 *
129128 * {{{
130129 * sumOfSquares(3, 2+2)
@@ -137,19 +136,19 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
137136 * 25
138137 * }}}
139138 *
140- * = The substitution model =
139+ * =The substitution model=
141140 *
142141 * This scheme of expression evaluation is called the ''substitution model''.
143142 *
144- * The idea underlying this model is that all evaluation does is ''reduce
145- * an expression to a value''.
143+ * The idea underlying this model is that all evaluation does is ''reduce an expression to a
144+ * value''.
146145 *
147146 * It can be applied to all expressions, as long as they have no side effects.
148147 *
149- * The substitution model is formalized in the λ-calculus, which gives
150- * a foundation for functional programming.
148+ * The substitution model is formalized in the λ-calculus, which gives a foundation for functional
149+ * programming.
151150 *
152- * = Termination =
151+ * =Termination=
153152 *
154153 * Does every expression reduce to a value (in a finite number of steps)?
155154 *
@@ -161,10 +160,10 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
161160 * loop
162161 * }}}
163162 *
164- * = Value Definitions and Termination =
163+ * =Value Definitions and Termination=
165164 *
166- * The difference between `val` and `def` becomes apparent when the right
167- * hand side does not terminate. Given
165+ * The difference between `val` and `def` becomes apparent when the right hand side does not
166+ * terminate. Given
168167 *
169168 * {{{
170169 * def loop: Int = loop
@@ -184,10 +183,9 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
184183 *
185184 * will lead to an infinite loop.
186185 *
187- * = Changing the evaluation strategy =
186+ * =Changing the evaluation strategy=
188187 *
189- * The interpreter reduces function arguments to values before rewriting the
190- * function application.
188+ * The interpreter reduces function arguments to values before rewriting the function application.
191189 *
192190 * One could alternatively apply the function to unreduced arguments.
193191 *
@@ -204,30 +202,27 @@ object DefinitionsAndEvaluation extends ScalaTutorialSection {
204202 * 25
205203 * }}}
206204 *
207- * = Call-by-name and call-by-value =
205+ * =Call-by-name and call-by-value=
208206 *
209- * The first evaluation strategy is known as ''call-by-value'',
210- * the second is known as ''call-by-name''.
207+ * The first evaluation strategy is known as ''call-by-value'', the second is known as
208+ * ''call-by-name''.
211209 *
212- * Both strategies reduce to the same final values
213- * as long as
210+ * Both strategies reduce to the same final values as long as
214211 *
215- * - the reduced expression consists of pure functions, and
216- * - both evaluations terminate.
212+ * - the reduced expression consists of pure functions, and
213+ * - both evaluations terminate.
217214 *
218- * Call-by-value has the advantage that it evaluates every function argument
219- * only once.
215+ * Call-by-value has the advantage that it evaluates every function argument only once.
220216 *
221- * Call-by-name has the advantage that a function argument is not evaluated if the
222- * corresponding parameter is unused in the evaluation of the function body.
217+ * Call-by-name has the advantage that a function argument is not evaluated if the corresponding
218+ * parameter is unused in the evaluation of the function body.
223219 *
224220 * Scala normally uses call-by-value.
225221 *
226- * = Exercise =
222+ * =Exercise=
227223 *
228- * Complete the following definition of the `triangleArea` function,
229- * which takes a triangle base and height as parameters and returns
230- * its area:
224+ * Complete the following definition of the `triangleArea` function, which takes a triangle base
225+ * and height as parameters and returns its area:
231226 */
232227 def triangleAreaExercise (res0 : Double , res1 : Double ): Unit = {
233228 def triangleArea (base : Double , height : Double ): Double =
0 commit comments