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
* 'Default arguments' -> 'Parameters with default values'. And lambda is not a parameter but an argument
Summarization of the team discussion:
- It's definitely ok to call it "optional parameters", but unfortunately
it's not a wide-spread term
- It's ok to say it in full "parameters with default values"
- It's ok to say "default value" (if it's clear from the context)
- "default parameters" and "default arguments" are slightly problematic
and it's better to avoid them
Discussion link:
https://jetbrains.slack.com/archives/C06E082M6/p1746713347805569
The commit fixes two problems:
1. Avoid using "default arguments" and "default parameters"
2. Lambda is not a parameter. It's an expression, and it's an argument
that corresponds to a parameter with functional type.
* Update anchors: #default-arguments -> #parameters-with-default-values
I missed some anchors in the previous commit
* Update all the remaining 'default arguments'
See the commit before the previous for motivation
* chore: add new term in compiler's guide mention
* update: replace mentions of optional parameters for consistency
* update: replace with parameters with default values
* chore: fix typo
---------
Co-authored-by: alepedroza <[email protected]>
`windowed()` provides more flexibility with optional parameters:
123
+
`windowed()` provides more flexibility regarding parameters with default values:
124
124
125
125
*`step` defines a distance between first elements of two adjacent windows. By default the value is 1, so the result contains windows starting from all elements. If you increase the step to 2, you will receive only windows starting from odd elements: first, third, and so on.
126
126
*`partialWindows` includes windows of smaller sizes that start from the elements at the end of the collection. For example, if you request windows of three elements, you can't build them for the last two elements. Enabling `partialWindows` in this case includes two more lists of sizes 2 and 1.
`joinToString()` builds a single `String` from the collection elements based on the provided arguments.
245
245
`joinTo()` does the same but appends the result to the given [`Appendable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-appendable/index.html) object.
246
246
247
-
When called with the default arguments, the functions return the result similar to calling `toString()` on the collection:
248
-
a `String` of elements' string representations separated by commas with spaces.
247
+
When called with the parameters' default values, the functions return the result similar to calling `toString()` on the collection:
248
+
a `String` of elements' string representations separated by commas with spaces.
> **Short summary**: Non-local return statements are no longer allowed in lambdas used as default arguments.
202
-
> This pattern previously compiled but led to runtime crashes. To migrate, rewrite the lambda to avoid non-local returns or move the logic outside the default argument.
201
+
> **Short summary**: Non-local return statements are no longer allowed in lambdas used as parameter's default value.
202
+
> This pattern previously compiled but led to runtime crashes. To migrate, rewrite the lambda to avoid non-local returns or move the logic outside the default value.
203
203
>
204
204
> **Deprecation cycle**:
205
205
>
206
-
> - 2.2.0: report an error for non-local returns in lambdas used as default argument values
206
+
> - 2.2.0: report an error for non-local returns in lambdas used as parameter's default value
Copy file name to clipboardExpand all lines: docs/topics/functions.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,10 @@ fun powerOf(
40
40
) { /*...*/ }
41
41
```
42
42
43
-
### Default arguments
43
+
### Parameters with default values
44
44
45
-
Function parameters can have default values, which are used when you skip the corresponding argument. This reduces the number
46
-
of overloads:
45
+
Function parameters can have default values, which are used when you skip the corresponding argument.
46
+
This reduces the number of overloads:
47
47
48
48
```kotlin
49
49
funread(
@@ -53,6 +53,8 @@ fun read(
53
53
) { /*...*/ }
54
54
```
55
55
56
+
Such parameters are also referred to as _optional parameters_.
57
+
56
58
A default value is set by appending `=` to the type.
57
59
58
60
Overriding methods always use the base method's default parameter values.
@@ -68,7 +70,7 @@ class B : A() {
68
70
}
69
71
```
70
72
71
-
If a default parameter precedes a parameter with no default value, the default value can only be used by calling
73
+
If a parameter with default value precedes a parameter with no default value, the default value can only be used by calling
72
74
the function with [named arguments](#named-arguments):
73
75
74
76
```kotlin
@@ -80,8 +82,8 @@ fun foo(
80
82
foo(baz =1) // The default value bar = 0 is used
81
83
```
82
84
83
-
If the last argument after default parameters is a [lambda](lambdas.md#lambda-expression-syntax),
84
-
you can pass it either as a named argument or [outside the parentheses](lambdas.md#passing-trailing-lambdas):
85
+
If the last parameter after all parameters with default values has a functional type,
86
+
then you can pass the corresponding [lambda](lambdas.md#lambda-expression-syntax) argument either as a named argument or [outside the parentheses](lambdas.md#passing-trailing-lambdas):
85
87
86
88
```kotlin
87
89
funfoo(
@@ -247,7 +249,7 @@ for the call). Infix functions must meet the following requirements:
247
249
* They must be member functions or [extension functions](extensions.md).
248
250
* They must have a single parameter.
249
251
* The parameter must not [accept variable number of arguments](#variable-number-of-arguments-varargs) and must have
250
-
no [default value](#default-arguments).
252
+
no [default value](#parameters-with-default-values).
Copy file name to clipboardExpand all lines: docs/topics/gsoc-2023.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,7 +138,7 @@ but the support for code that uses composition instead of inheritance has yet to
138
138
139
139
The main problem of working with code that heavily uses composition is parameter forwarding.
140
140
In particular:
141
-
* The IDE doesn't suggest completing parameter declarations that can be forwarded as arguments to other functions that currently use default arguments.
141
+
* The IDE doesn't suggest completing parameter declarations that can be forwarded as arguments to other functions that currently use default parameter values.
142
142
* The IDE doesn't rename the chain of forwarded parameters.
143
143
* The IDE doesn't provide any quick-fixes that fill in all the required arguments with parameters that can be forwarded.
0 commit comments