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
Conversation
1d33624
to
8dc51b9
Compare
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"}
8dc51b9
to
8080983
Compare
Not a big fan of the default |
@mhermier What do you suggest? I think that it's a simple and useful implementation to give a set-like type in Wren.
|
I suggest that `var a = { 1, 2, 3}` is equivalent to `var a = { 1: 1, 2: 2,
3: 3}`. Since most values are evalued to true, it should be equivalent to
your suggestion.
Le 10 juin 2018 8:16 PM, "Bruno Macabeus" <notifications@github.com> a
écrit :
@mhermier <https://github.com/mhermier> What do you suggest? I think that
it's a simple and useful implementation to give a set-like feature 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
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#558 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AY7blbK9y_mjvwfifP2WUU3-nGp3uj60ks5t7WJkgaJpZM4UhkT5>
.
|
But then you can't put |
There is no problems with true, there are advantage of having the key back
has values. When the keys match, there is no guarantee that it is the same
object, so you have to traverse the list of keys to get the key back and
use that instance.
|
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? |
Because this immutability is an implementation detail of the map. It should
not restrict language design.
|
Thanks for the PR! |
Closes #137
This code
now is the same of: