@@ -12,6 +12,7 @@ title: SIP-NN - Allow referring to other arguments in default parameters
12
12
| ---------------| ------------------|
13
13
| Jan 11th 2017 | Initial Draft |
14
14
| Jan 12th 2017 | Initial Feedback |
15
+ | Jan 16th 2017 | Minor Changes |
15
16
16
17
## Introduction
17
18
Currently there is no way to refer to other arguments in the default parameters list:
@@ -26,16 +27,16 @@ The workaround to achieve this is by using a curried-function:
26
27
def substring (s : String , start : Int = 0 )(end : Int = s.length): String
27
28
```
28
29
29
- However, the above workaround is not always suitable in certain situations.
30
+ However, the above workaround is not always suitable in all situations since you may not want a curried function .
30
31
31
32
The other more verbose alternative is by overloading:
32
-
33
33
``` scala
34
- def substring (s : String , start : Int = 0 , end : Int = s.length ): String
34
+ def substring (s : String , start : Int ): String
35
35
= substring(s, start = 0 , end = s.length)
36
- def substring (s : String , start : Int , end : Int ): String
36
+ def substring (s : String , start : Int = 0 , end : Int ): String
37
37
```
38
38
39
+ The above is quite verbose as it required 1 extra function definition per argument that refers other args.
39
40
40
41
### Proposal
41
42
Allow to refer to *** any*** parameters in the same (or left) curried parameter list:
@@ -59,6 +60,10 @@ We should also be able to refer to ***multiple*** parameters:
59
60
def binarySearch (start : Int , end : Int , middle : Int = (start + end)/ 2 ) // Legal
60
61
```
61
62
63
+ # Motivating examples:
64
+
65
+ TBD
66
+
62
67
## Interactions with other syntax
63
68
64
69
#### Partially Applied Functions:
0 commit comments