Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

?= operator (assign if nil) #355

Open
aleclarson opened this issue Feb 22, 2018 · 6 comments
Open

?= operator (assign if nil) #355

aleclarson opened this issue Feb 22, 2018 · 6 comments

Comments

@aleclarson
Copy link

aleclarson commented Feb 22, 2018

This code..

foo ?= {}

-- If the ?. operator is added:
foo?.bar ?= {blue: true}

..would compile to:

local foo
if foo == nil then
  foo = {}
end

if foo ~= nil and foo.bar == nil then
  foo.bar = {blue = true}
end

What do you think, @leafo? Have you considered this feature already?

Cheers!

@aleclarson
Copy link
Author

aleclarson commented Feb 22, 2018

I edited this thread to remove mention of the ?. operator,
since it has been discussed already: #285 #122

@leafo hasn't directly addressed those issues yet.

...but back in September 2016, he said:

I'm not really interested in adding a new operator

I'm of the opinion that these operators are extremely useful!

@RyanSquared
Copy link
Contributor

do you mind closing this issue as we already have other issues open for this purpose?

@aleclarson
Copy link
Author

aleclarson commented Feb 22, 2018

@RyanSquared There is no issue proposing the ?= operator, but there is this comment mentioning it. So I think there's reason to keep this open.

@RyanSquared
Copy link
Contributor

I don't think it's reasonable to create a new issue for every comment on a post suggesting something. The operators are directly linked and - for me at least - that comment is still in the primary fold when loading the page.

(perhaps I should create a new issue to leave this comment?)

@aleclarson
Copy link
Author

aleclarson commented Feb 22, 2018

@RyanSquared I don't think a slippery slope exists here. Proposals for new operators should get their own dedicated threads for discussing their pros and cons exclusively. I'll edit this thread to focus on
?= since ?. has been discussed. I think |> should have its own thread, too.

@vendethiel
Copy link

The two features are different:

a?.b vs a ? b.
CoffeeScript uses the same symbol, but C# for example doesn't.
CoffeeScript actually even has a 3rd meaning: a? b, which is x(b) if typeof(x = a) is function.

@aleclarson aleclarson changed the title ?= and ? operators ?= operator (assign if nil) Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants