Merge: Named arguments
authorJean Privat <jean@pryen.org>
Sat, 25 Apr 2015 02:19:15 +0000 (09:19 +0700)
committerJean Privat <jean@pryen.org>
Sat, 25 Apr 2015 02:19:15 +0000 (09:19 +0700)
commitfaf746de617a163896dd409c540f254e78f310a1
tree934e644fd9d34b8a8e733bf2a1fcd9620d3ab0a7
parentaa7db728f58476c4732404cde86a54ad27205cbc
parent12ba9924aa07aea266e1cfe38b243e17dcd0dc03
Merge: Named arguments

Named arguments allows the caller to specify some subset of arguments it wants to call.
This PR introduce a syntax for callers inspired from the Python one (the Ruby one uses columns that clashes with types declaration).

~~~nit
format(linewidth=80, separator=":", indent=true)
~~~

The specification tries to be as simple as possible

* Only default parameters can be passed by name; because the other are mandatory.
  This restriction is also useful to avoid to specify additional rules, like the last parameter of assignment methods, because the ones on default arguments apply.

~~~nit
fun foo(a,b: nullable Int) do ...
foo(b=1)
foo(null,1) # equivalent
~~~

* Named arguments can appear anywhere (not necessarily at the end)

~~~nit
fun foo(a: Int, b: nulable Int)
foo(b=1,2)
foo(2,1) # equivalent
~~~

* The order of evaluation is the order of the arguments (not the order of the parameters).
  I think this is more POLA this way.

* The names to use are the one of the statically designated method declaration (not the introduction).
  This one is problematic because the language permit the name of parameters to change in redefinitions.
  But in case of errors or in a IDE it is often more useful to point the most precise method definition.

The implementation was trivial because the hard work was already done in the previous PR.

This PR was unlocked by #1280

Pull-Request: #1281
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Etienne M. Gagnon <egagnon@j-meg.com>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>