@@ -12,6 +12,7 @@ title: SIP-NN - Allow referring to other arguments in default parameters
1212| ---------------| ------------------|
1313| Jan 11th 2017 | Initial Draft |
1414| Jan 12th 2017 | Initial Feedback |
15+ | Jan 16th 2017 | Minor Changes |
1516
1617## Introduction
1718Currently 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:
2627def substring (s : String , start : Int = 0 )(end : Int = s.length): String
2728```
2829
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 .
3031
3132The other more verbose alternative is by overloading:
32-
3333``` scala
34- def substring (s : String , start : Int = 0 , end : Int = s.length ): String
34+ def substring (s : String , start : Int ): String
3535 = 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
3737```
3838
39+ The above is quite verbose as it required 1 extra function definition per argument that refers other args.
3940
4041### Proposal
4142Allow 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:
5960def binarySearch (start : Int , end : Int , middle : Int = (start + end)/ 2 ) // Legal
6061```
6162
63+ # Motivating examples:
64+
65+ TBD
66+
6267## Interactions with other syntax
6368
6469#### Partially Applied Functions:
0 commit comments