summaryrefslogtreecommitdiff
path: root/spec/04-basic-declarations-and-definitions.md
diff options
context:
space:
mode:
Diffstat (limited to 'spec/04-basic-declarations-and-definitions.md')
-rw-r--r--spec/04-basic-declarations-and-definitions.md27
1 files changed, 18 insertions, 9 deletions
diff --git a/spec/04-basic-declarations-and-definitions.md b/spec/04-basic-declarations-and-definitions.md
index 84459d7639..5e055228f1 100644
--- a/spec/04-basic-declarations-and-definitions.md
+++ b/spec/04-basic-declarations-and-definitions.md
@@ -88,10 +88,10 @@ The class definition `case class X(), Y(n: Int) extends Z` expands to
`case class X extends Z; case class Y(n: Int) extends Z`.
- The object definition `case object Red, Green, Blue extends Color`~
expands to
-```
+```scala
case object Red extends Color
case object Green extends Color
-case object Blue extends Color .
+case object Blue extends Color
```
-->
@@ -144,7 +144,7 @@ value definition `val $p$ = $e$` is expanded as follows:
val $\$ x$ = $e$ match {case $p$ => ($x_1 , \ldots , x_n$)}
val $x_1$ = $\$ x$._1
$\ldots$
-val $x_n$ = $\$ x$._n .
+val $x_n$ = $\$ x$._n
```
Here, $\$ x$ is a fresh name.
@@ -595,9 +595,9 @@ ParamType ::= Type
| Type ‘*’
```
-A function declaration has the form `def $f\,\mathit{psig}$: $T$`, where
+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. A function definition
+signature and $T$ is its result type. 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. A parameter
signature consists of an optional type parameter clause `[$\mathit{tps}\,$]`,
@@ -612,13 +612,13 @@ result type, if one is given. 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.
-A type parameter clause $\mathit{tps}$ consists of one or more
+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. 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.
-A value parameter clause $\mathit{ps}$ consists of zero or more formal
+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.
@@ -669,6 +669,15 @@ def f(a: Int = 0)(b: Int = a + 1) = b // OK
f(10)() // returns 11 (not 1)
```
+If an [implicit argument](07-implicits.html#implicit-parameters)
+is not found by implicit search, it may be supplied using a default argument.
+
+```scala
+implicit val i: Int = 2
+def f(implicit x: Int, s: String = "hi") = s * x
+f // "hihi"
+```
+
### By-Name Parameters
```ebnf
@@ -774,12 +783,12 @@ FunDef ::= FunSig [nl] ‘{’ Block ‘}’
Special syntax exists for procedures, i.e. functions that return the
`Unit` value `()`.
-A procedure declaration is a function declaration where the result type
+A _procedure declaration_ is a function declaration where the result type
is omitted. 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`.
-A procedure definition is a function definition where the result type
+A _procedure definition_ is a function definition where the result type
and the equals sign are omitted; its defining expression must be a block.
E.g., `def $f$($\mathit{ps}$) {$\mathit{stats}$}` is equivalent to
`def $f$($\mathit{ps}$): Unit = {$\mathit{stats}$}`.