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
Copy file name to clipboardExpand all lines: docs/_spec/04-basic-declarations-and-definitions.md
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -183,7 +183,7 @@ VarDef ::= PatDef
183
183
| ids ‘:’ Type ‘=’ ‘_’
184
184
```
185
185
186
-
A variable declaration `var ´x´: ´T´` is equivalent to the declarations of both a _getter function_ ´x´ *and* a _setter function_`´x´_=`:
186
+
A variable declaration `var ´x´: ´T´` is equivalent to the declarations of both a _getter method_ ´x´ *and* a _setter method_`´x´_=`:
187
187
188
188
```scala
189
189
def ´x´: ´T´
@@ -215,9 +215,9 @@ The default value depends on the type ´T´ as follows:
215
215
|`()`|`Unit`|
216
216
|`null`| all other types |
217
217
218
-
When they occur as members of a template, both forms of variable definition also introduce a getter function ´x´ which returns the value currently assigned to the variable, as well as a setter function`´x´_=` which changes the value currently assigned to the variable.
219
-
The functions have the same signatures as for a variable declaration.
220
-
The template then has these getter and setter functions as members, whereas the original variable cannot be accessed directly as a template member.
218
+
When they occur as members of a template, both forms of variable definition also introduce a getter method ´x´ which returns the value currently assigned to the variable, as well as a setter method`´x´_=` which changes the value currently assigned to the variable.
219
+
The methods have the same signatures as for a variable declaration.
220
+
The template then has these getter and setter methods as members, whereas the original variable cannot be accessed directly as a template member.
221
221
222
222
###### Example
223
223
@@ -287,7 +287,7 @@ A _type alias_ `type ´t´ = ´T´` defines ´t´ to be an alias name for the ty
287
287
The left hand side of a type alias may have a type parameter clause, e.g. `type ´t´[´\mathit{tps}\,´] = ´T´`.
288
288
The scope of a type parameter extends over the right hand side ´T´ and the type parameter clause ´\mathit{tps}´ itself.
289
289
290
-
The scope rules for [definitions](#basic-declarations-and-definitions) and [type parameters](#function-declarations-and-definitions) make it possible that a type name appears in its own bound or in its right-hand side.
290
+
The scope rules for [definitions](#basic-declarations-and-definitions) and [type parameters](#method-declarations-and-definitions) make it possible that a type name appears in its own bound or in its right-hand side.
291
291
However, it is a static error if a type alias refers recursively to the defined type constructor itself.
292
292
That is, the type ´T´ in a type alias `type ´t´[´\mathit{tps}\,´] = ´T´` may not refer directly or indirectly to the name ´t´.
293
293
It is also an error if an abstract type is directly or indirectly its own upper or lower bound.
Type parameters appear in type definitions, class definitions, and function definitions.
349
+
Type parameters appear in type definitions, class definitions, and method definitions.
350
350
In this section we consider only type parameter definitions with lower bounds `>: ´L´` and upper bounds `<: ´U´` whereas a discussion of context bounds `: ´U´` and view bounds `<% ´U´` is deferred to [here](07-implicits.html#context-bounds-and-view-bounds).
351
351
352
352
The most general form of a proper type parameter is
@@ -497,7 +497,7 @@ abstract class OutputChannel[-A] {
497
497
With that annotation, we have that `OutputChannel[AnyRef]` conforms to `OutputChannel[String]`.
498
498
That is, a channel on which one can write any object can substitute for a channel on which one can write only strings.
499
499
500
-
## Function Declarations and Definitions
500
+
## Method Declarations and Definitions
501
501
502
502
```ebnf
503
503
Dcl ::= ‘def’ FunDcl
@@ -515,23 +515,23 @@ ParamType ::= Type
515
515
| Type ‘*’
516
516
```
517
517
518
-
A _function declaration_ has the form `def ´f\,\mathit{psig}´: ´T´`, where ´f´ is the function's name, ´\mathit{psig}´ is its parameter signature and ´T´ is its result type.
519
-
A _function definition_`def ´f\,\mathit{psig}´: ´T´ = ´e´` also includes a _function body_ ´e´, i.e. an expression which defines the function's result.
518
+
A _method declaration_ has the form `def ´f\,\mathit{psig}´: ´T´`, where ´f´ is the method's name, ´\mathit{psig}´ is its parameter signature and ´T´ is its result type.
519
+
A _method definition_`def ´f\,\mathit{psig}´: ´T´ = ´e´` also includes a _method body_ ´e´, i.e. an expression which defines the method's result.
520
520
A parameter signature consists of an optional type parameter clause `[´\mathit{tps}\,´]`, followed by zero or more value parameter clauses `(´\mathit{ps}_1´)...(´\mathit{ps}_n´)`.
521
521
Such a declaration or definition introduces a value with a (possibly polymorphic) method type whose parameter types and result type are as given.
522
522
523
-
The type of the function body is expected to [conform](06-expressions.html#expression-typing) to the function's declared result type, if one is given.
524
-
If the function definition is not recursive, the result type may be omitted, in which case it is determined from the packed type of the function body.
523
+
The type of the method body is expected to [conform](06-expressions.html#expression-typing) to the method's declared result type, if one is given.
524
+
If the method definition is not recursive, the result type may be omitted, in which case it is determined from the packed type of the method body.
525
525
526
526
A _type parameter clause_ ´\mathit{tps}´ consists of one or more [type declarations](#type-declarations-and-type-aliases), which introduce type parameters, possibly with bounds.
527
-
The scope of a type parameter includes the whole signature, including any of the type parameter bounds as well as the function body, if it is present.
527
+
The scope of a type parameter includes the whole signature, including any of the type parameter bounds as well as the method body, if it is present.
528
528
529
529
A _value parameter clause_ ´\mathit{ps}´ consists of zero or more formal parameter bindings such as `´x´: ´T´` or `´x: T = e´`, which bind value parameters and associate them with their types.
530
530
531
531
### Default Arguments
532
532
533
533
Each value parameter declaration may optionally define a default argument.
534
-
The default argument expression ´e´ is type-checked with an expected type ´T'´ obtained by replacing all occurrences of the function's type parameters in ´T´ by the undefined type.
534
+
The default argument expression ´e´ is type-checked with an expected type ´T'´ obtained by replacing all occurrences of the method's type parameters in ´T´ by the undefined type.
535
535
536
536
For every parameter ´p_{i,j}´ with a default argument a method named `´f\$´default´\$´n` is generated which computes the default argument expression.
537
537
Here, ´n´ denotes the parameter's position in the method declaration.
@@ -555,7 +555,7 @@ def compare´\$´default´\$´1[T]: Int = 0
555
555
defcompare´\$´default´\$´2[T](a: T):T= a
556
556
```
557
557
558
-
The scope of a formal value parameter name ´x´ comprises all subsequent parameter clauses, as well as the method return type and the function body, if they are given.
558
+
The scope of a formal value parameter name ´x´ comprises all subsequent parameter clauses, as well as the method return type and the method body, if they are given.
559
559
Both type parameter names and value parameter names must be pairwise distinct.
560
560
561
561
A default value which depends on earlier parameters uses the actual arguments if they are provided, not the default arguments.
@@ -582,7 +582,7 @@ ParamType ::= ‘=>’ Type
582
582
583
583
The type of a value parameter may be prefixed by `=>`, e.g. `´x´: => ´T´`.
584
584
The type of such a parameter is then the parameterless method type `=> ´T´`.
585
-
This indicates that the corresponding argument is not evaluated at the point of function application, but instead is evaluated at each use within the function.
585
+
This indicates that the corresponding argument is not evaluated at the point of method application, but instead is evaluated at each use within the method.
586
586
That is, the argument is evaluated using _call-by-name_.
587
587
588
588
The by-name modifier is disallowed for parameters of classes that carry a `val` or `var` prefix, including parameters of case classes for which a `val` prefix is implicitly generated.
@@ -654,11 +654,11 @@ FunDcl ::= FunSig
654
654
FunDef ::= FunSig [nl] ‘{’ Block ‘}’
655
655
```
656
656
657
-
Special syntax exists for procedures, i.e. functions that return the `Unit` value `()`.
658
-
A _procedure declaration_ is a function declaration where the result type is omitted.
657
+
Special syntax exists for procedures, i.e. methods that return the `Unit` value `()`.
658
+
A _procedure declaration_ is a method declaration where the result type is omitted.
659
659
The result type is then implicitly completed to the `Unit` type. E.g., `def ´f´(´\mathit{ps}´)` is equivalent to `def ´f´(´\mathit{ps}´): Unit`.
660
660
661
-
A _procedure definition_ is a function definition where the result type and the equals sign are omitted; its defining expression must be a block.
661
+
A _procedure definition_ is a method definition where the result type and the equals sign are omitted; its defining expression must be a block.
662
662
E.g., `def ´f´(´\mathit{ps}´) {´\mathit{stats}´}` is equivalent to `def ´f´(´\mathit{ps}´): Unit = {´\mathit{stats}´}`.
A class member definition ´m´ that overrides some other function ´m'´ in a base class of ´C´ may leave out the return type, even if it is recursive.
690
-
In this case, the return type ´R'´ of the overridden function ´m'´, seen as a member of ´C´, is taken as the return type of ´m´ for each recursive invocation of ´m´.
689
+
A class member definition ´m´ that overrides some other method ´m'´ in a base class of ´C´ may leave out the return type, even if it is recursive.
690
+
In this case, the return type ´R'´ of the overridden method ´m'´, seen as a member of ´C´, is taken as the return type of ´m´ for each recursive invocation of ´m´.
691
691
That way, a type ´R´ for the right-hand side of ´m´ can be determined, which is then taken as the return type of ´m´.
692
692
Note that ´R´ may be different from ´R'´, as long as ´R´ conforms to ´R'´.
693
693
@@ -709,7 +709,7 @@ Here, it is OK to leave out the result type of `factorial` in `C`, even though t
709
709
\label{sec:overloaded-defs}
710
710
\todo{change}
711
711
712
-
An overloaded definition is a set of ´n > 1´ value or function
712
+
An overloaded definition is a set of ´n > 1´ value or method
713
713
definitions in the same statement sequence that define the same name,
714
714
binding it to types `´T_1 \commadots T_n´`, respectively.
715
715
The individual definitions are called _alternatives_. Overloaded
Copy file name to clipboardExpand all lines: docs/_spec/05-classes-and-objects.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -603,7 +603,7 @@ The self constructor invocation must construct a generic instance of the class.
603
603
I.e. if the class in question has name ´C´ and type parameters `[´\mathit{tps}\,´]`, then a self constructor invocation must generate an instance of `´C´[´\mathit{tps}\,´]`; it is not permitted to instantiate formal type parameters.
604
604
605
605
The signature and the self constructor invocation of a constructor definition are type-checked and evaluated in the scope which is in effect at the point of the enclosing class definition, augmented by any type parameters of the enclosing class and by any [early definitions](#early-definitions) of the enclosing template.
606
-
The rest of the constructor expression is type-checked and evaluated as a function body in the current class.
606
+
The rest of the constructor expression is type-checked and evaluated as a method body in the current class.
607
607
608
608
If there are auxiliary constructors of a class ´C´, they form together with ´C´'s primary [constructor](#class-definitions) an overloaded constructor definition.
609
609
The usual rules for [overloading resolution](06-expressions.html#overloading-resolution) apply for constructor invocations of ´C´, including for the self constructor invocations in the constructor expressions themselves.
0 commit comments