[ 
https://issues.apache.org/jira/browse/GROOVY-3795?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-3795:
--------------------------------
    Fix Version/s:     (was: 4.x)

> Provide a consistent notation between method calls and index parameters with 
> maps as index or param
> ---------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-3795
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3795
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler, parser-antlr2
>    Affects Versions: 1.6.4, 1.7-beta-1
>            Reporter: Guillaume Sauthier
>            Priority: Major
>
> We can pass "named arguments" in method calls, making the following 
> equivalent:
> {code}
> foo.method( [a: 1, b: 2] )
> foo.method( a: 1, b: 2 ) // square brackets omitted
> {code}
> We should allow the same notations for indices in the subscript notation:
> {code}
> someObject[ [a: 1, b: 2] ]
> someObject[ a: 1, b: 2 ]
> {code}
> Currently, it's not possible to use map entries or maps as indices for the 
> subscript notation.
> So the idea of this JIRA improvement is to allow this.
> And people would be able to use a getAt(Map) method on their objects to have 
> access to that notation.
> Some further remarks:
> * with method calls, it's even possible to use the foo.method a: 1, b: 2 
> notation, but of course, this is not possible with the subscript notation, as 
> we need the square brackets
> * an example of using that map as index idea is for example to represent text 
> pointers or text selections in some document handling application: 
> {code}
> def bookmark = someText[ 10 : 20 ] // a bookmark on line 10 column 20, or 
> perhaps even chapter 10 paragraph 20
> def selection = someText [ 10:20, 11:5 ] // a text selection between line 10 
> column 20 and line 11 column 5
> {code}
> * the sole drawback with map entries as indices is when we want to use 
> variables for line numbers, as we have to use parens around the "key" so as 
> not to have a textual key:
> {code}
> def (line, column) = [10, 20]
> def bookmark = someText [ (line): column ]
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to