[ https://issues.apache.org/jira/browse/GROOVY-5306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-5306: ------------------------------ Issue Type: New Feature (was: Improvement) > [PARROT] Add "a ?= 2" support (Elvis assignment): should be expanded to "a = > a == null ? 2 : a" > ----------------------------------------------------------------------------------------------- > > Key: GROOVY-5306 > URL: https://issues.apache.org/jira/browse/GROOVY-5306 > Project: Groovy > Issue Type: New Feature > Components: syntax > Reporter: Rodrigo Rosenfeld Rosas > Assignee: Daniel Sun > Priority: Major > Fix For: 3.0.0-alpha-1, 2.6.0-alpha-1 > > > I've suggested last week the creation of the "?:=" constructor in Groovy: > https://jira.codehaus.org/browse/GROOVY-5291 > It was rejected and a new JIRA was requested to be created with a new > operator. > Then, I've talked to the Grails users in their mailing list to get some > feedback, which can be read here: > http://grails.1312388.n4.nabble.com/Help-improving-Groovy-syntax-tt4384137.html > Then, Phil DeJarnett has suggested using "?=" instead of "?:=". Not only I > preferred this suggestion, but I was changed my mind about its meaning too. > It would be used as a caching/memoization operator mostly. It would be > similar to Ruby's "||=", except for this specific situation: > Ruby: > {code} > a = nil > a ||= false # a will be false > a ||= true # a will be true > {code} > That is why "a ||= value" is expanded to "a = a || value" > But for caching/memoization, I'd prefer "a ?= value" to be expanded to "a = a > == null ? value : a". This way we would have: > Proposed Groovy syntax: > {code} > def a = null > a ?= false; assert a == false > a ?= true; assert a == true > a = null; a ?= new Object(); assert a instanceof Object > {code} > I'll actually fill a new ticket on Ruby Redmine too for proposing the same > syntax and semanthics :) -- This message was sent by Atlassian JIRA (v7.6.3#76005)