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

Add syntax sugar for maps #558

Closed
wants to merge 1 commit into from

Conversation

macabeus
Copy link

Closes #137

This code

var set1 = {1, 2, 3}
var set2 = {"foo", "bar": "baz"}

now is the same of:

var set1 = {1: true, 2: true, 3: true}
var set2 = {"foo": true, "bar": "baz"}

Closes wren-lang#137

This code

var set1 = {1, 2, 3}
var set2 = {"foo", "bar": "baz"}

now is the same of:

var set1 = {1: true, 2: true, 3: true}
var set2 = {"foo": true, "bar": "baz"}
@mhermier
Copy link
Contributor

Not a big fan of the default true value assignment. Duplicating the key to the value sounds more logical to me. But it has other problems/implications...

@macabeus
Copy link
Author

macabeus commented Jun 10, 2018

@mhermier What do you suggest? I think that it's a simple and useful implementation to give a set-like type in Wren.

true is a good choice in order to do something like:

> var x = {1, 2, 3}
> if (x[1]) { System.print("foo") } //> "foo"
> if (x[5]) { System.print("foo") } //> nil

@mhermier
Copy link
Contributor

mhermier commented Jun 10, 2018 via email

@Akaricchi
Copy link

But then you can't put false in a "set" like this, which is a bit counter-intuitive. What exactly is wrong with true?

@mhermier
Copy link
Contributor

mhermier commented Jun 11, 2018 via email

@Akaricchi
Copy link

https://github.com/munificent/wren/blob/master/src/vm/wren_value.c#L389

Every object that can be hashed is immutable. Why would user code ever need to care whether two immutable objects of equal value are actually the same object or not?

@mhermier
Copy link
Contributor

mhermier commented Jun 11, 2018 via email

@ruby0x1
Copy link
Member

ruby0x1 commented Sep 18, 2019

Thanks for the PR!
Right now, I don't feel like this fits just right with Wren as is, so I'm gonna close it.

@ruby0x1 ruby0x1 closed this Sep 18, 2019
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

Successfully merging this pull request may close these issues.

Set syntax sugar for maps
4 participants