You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "mgroovy (JIRA)" <ji...@apache.org> on 2018/01/16 23:09:00 UTC

[jira] [Created] (GROOVY-8451) Non-Map-Based Named Parameter Support

mgroovy created GROOVY-8451:
-------------------------------

             Summary: Non-Map-Based Named Parameter Support
                 Key: GROOVY-8451
                 URL: https://issues.apache.org/jira/browse/GROOVY-8451
             Project: Groovy
          Issue Type: Improvement
            Reporter: mgroovy


* Groovy should support named parameters as available in many other languages:
https://en.wikipedia.org/wiki/Named_parameter
* The suggested syntax and semantics are the ones used by the Kotlin programming language
https://kotlinlang.org/docs/reference/functions.html#named-arguments
since 
## using the assignment operator to define named parameter values 
*** Seems a very organic choice in the Java family of languages
*** Differentiates the syntax clearly from the alternate/existing Groovy map based named parameter support
## The design decisions are relatively straightforward
## Kotlin syntax is close to Groovy (apart from some odd deviations), so what works there should work in Groovy
* Features:
** Parameters are assigned a value prioritized in the following order:
### positional value
### named parameter value
### default value
** Parameters which do not have a default value must be given when calling the method
** All non-named parameters must come before named-parameters
** Named parameters can be given in any order
* Example:
{code}
void foo(final x0, final x1, final x2 = defVal2, final x3 = defVal3, final x4 = defVal4) { /* ... */ }
// x0 = val0, x1 = val1, x2 = val2, x3 = defVal3, x4 = val4 
foo(val0, x2 = val2, x4 = val4, x1 = val1) 
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)