Skip to content

Commit e001500

Browse files
committed
Replace function by method wherever possible
1 parent ab27c18 commit e001500

7 files changed

+41
-41
lines changed

docs/_spec/01-lexical-syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ A single new line token is accepted
234234
> (y: Int) = x + y
235235
> ```
236236
>
237-
> With an additional newline character, the same code is interpreted as an abstract function definition and a syntactically illegal statement:
237+
> With an additional newline character, the same code is interpreted as an abstract method definition and a syntactically illegal statement:
238238
>
239239
> ```scala
240240
> def func(x: Int)

docs/_spec/03-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ An argument type of the form ´\Rightarrow T´ represents a [call-by-name parame
335335

336336
Function types associate to the right, e.g. ´S \Rightarrow T \Rightarrow U´ is the same as ´S \Rightarrow (T \Rightarrow U)´.
337337

338-
Function types are shorthands for class types that define `apply` functions.
338+
Function types are shorthands for class types that define an `apply` method.
339339
Specifically, the ´n´-ary function type ´(T_1 , \ldots , T_n) \Rightarrow U´ is a shorthand for the class type `Function´_n´[´T_1´ , … , ´T_n´, ´U´]`.
340340
Such class types are defined in the Scala library for ´n´ between 0 and 22 as follows.
341341

docs/_spec/04-basic-declarations-and-definitions.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ VarDef ::= PatDef
183183
| ids ‘:’ Type ‘=’ ‘_’
184184
```
185185

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´_=`:
187187

188188
```scala
189189
def ´x´: ´T´
@@ -215,9 +215,9 @@ The default value depends on the type ´T´ as follows:
215215
|`()` | `Unit` |
216216
|`null` | all other types |
217217

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.
221221

222222
###### Example
223223

@@ -287,7 +287,7 @@ A _type alias_ `type ´t´ = ´T´` defines ´t´ to be an alias name for the ty
287287
The left hand side of a type alias may have a type parameter clause, e.g. `type ´t´[´\mathit{tps}\,´] = ´T´`.
288288
The scope of a type parameter extends over the right hand side ´T´ and the type parameter clause ´\mathit{tps}´ itself.
289289

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.
291291
However, it is a static error if a type alias refers recursively to the defined type constructor itself.
292292
That is, the type ´T´ in a type alias `type ´t´[´\mathit{tps}\,´] = ´T´` may not refer directly or indirectly to the name ´t´.
293293
It is also an error if an abstract type is directly or indirectly its own upper or lower bound.
@@ -346,7 +346,7 @@ VariantTypeParam ::= {Annotation} [‘+’ | ‘-’] TypeParam
346346
TypeParam ::= (id | ‘_’) [TypeParamClause] [‘>:’ Type] [‘<:’ Type] [‘:’ Type]
347347
```
348348

349-
Type parameters appear in type definitions, class definitions, and function definitions.
349+
Type parameters appear in type definitions, class definitions, and method definitions.
350350
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).
351351

352352
The most general form of a proper type parameter is
@@ -497,7 +497,7 @@ abstract class OutputChannel[-A] {
497497
With that annotation, we have that `OutputChannel[AnyRef]` conforms to `OutputChannel[String]`.
498498
That is, a channel on which one can write any object can substitute for a channel on which one can write only strings.
499499

500-
## Function Declarations and Definitions
500+
## Method Declarations and Definitions
501501

502502
```ebnf
503503
Dcl ::= ‘def’ FunDcl
@@ -515,23 +515,23 @@ ParamType ::= Type
515515
| Type ‘*’
516516
```
517517

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.
520520
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´)`.
521521
Such a declaration or definition introduces a value with a (possibly polymorphic) method type whose parameter types and result type are as given.
522522

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.
525525

526526
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.
528528

529529
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.
530530

531531
### Default Arguments
532532

533533
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.
535535

536536
For every parameter ´p_{i,j}´ with a default argument a method named `´f\$´default´\$´n` is generated which computes the default argument expression.
537537
Here, ´n´ denotes the parameter's position in the method declaration.
@@ -555,7 +555,7 @@ def compare´\$´default´\$´1[T]: Int = 0
555555
def compare´\$´default´\2[T](a: T): T = a
556556
```
557557

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.
559559
Both type parameter names and value parameter names must be pairwise distinct.
560560

561561
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
582582

583583
The type of a value parameter may be prefixed by `=>`, e.g. `´x´: => ´T´`.
584584
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.
586586
That is, the argument is evaluated using _call-by-name_.
587587

588588
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
654654
FunDef ::= FunSig [nl] ‘{’ Block ‘}’
655655
```
656656

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.
659659
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`.
660660

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.
662662
E.g., `def ´f´(´\mathit{ps}´) {´\mathit{stats}´}` is equivalent to `def ´f´(´\mathit{ps}´): Unit = {´\mathit{stats}´}`.
663663

664664
###### Example
@@ -686,8 +686,8 @@ object Terminal extends Writer {
686686

687687
### Method Return Type Inference
688688

689-
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´.
691691
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´.
692692
Note that ´R´ may be different from ´R'´, as long as ´R´ conforms to ´R'´.
693693

@@ -709,7 +709,7 @@ Here, it is OK to leave out the result type of `factorial` in `C`, even though t
709709
\label{sec:overloaded-defs}
710710
\todo{change}
711711
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
713713
definitions in the same statement sequence that define the same name,
714714
binding it to types `´T_1 \commadots T_n´`, respectively.
715715
The individual definitions are called _alternatives_. Overloaded

docs/_spec/05-classes-and-objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ The self constructor invocation must construct a generic instance of the class.
603603
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.
604604

605605
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.
607607

608608
If there are auxiliary constructors of a class ´C´, they form together with ´C´'s primary [constructor](#class-definitions) an overloaded constructor definition.
609609
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

Comments
 (0)