Skip to content

Need to use .set and .get #12

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

Open
natew opened this issue Apr 10, 2015 · 5 comments
Open

Need to use .set and .get #12

natew opened this issue Apr 10, 2015 · 5 comments

Comments

@natew
Copy link

natew commented Apr 10, 2015

I don't see anywhere in docs but I'd like to treat my immutable data structures like normal JS ones, in that I dislike having to use get and set rather than just =. I assumed this spec would have something along those lines but I didn't see it explicitly.

@nmn
Copy link
Contributor

nmn commented Apr 10, 2015

The problem is that a normal = can't work for most cases.

(I don't see any mention of .get and .set in the documents for vectors. (Which is probably an oversight))

For example, take the example of a vector.

var a = #[1, 2, 3, 4]

Now, of course, it should be possible to easily read values:

a[0] === 1

But you can't use assignment to update the vector:

a[0] = 9 // Doesn't work

This is because, by definition, these data structures are immutable.

a = a.set(0, 9)  // sadly there is no mentions of a .set in the docs so far.

This is actually the same way that strings work in Javascript:

var str = 'abc'
str = str + 'def'

str[1] === 'b'
str[1] = 'c' // doesn't work

The only way to assignment work reliably would be to create a new value on every assignment. This can technically work, but seems to be complicated and confusing for Javascript.

@natew
Copy link
Author

natew commented Apr 10, 2015

Actually I apologize I wrote this late before I forgot about it but I don't think set is as important, just being able to get without explicit .get would be nice.

@nmn
Copy link
Contributor

nmn commented Apr 11, 2015

@natew I agree with the subscript based get. But It would only work for vectors and records, as Maps take non-string, non-number strings as well.

@andersekdahl
Copy link

As much as I'd like to be able to do avoid using .get and .set, I think that it's quite important to be able to polyfill this feature. Even though you could transform vector[0] to vector.get(0) the impossible part is to know when a variable is an immutable vector and not an array, which means that it cannot be polyfilled.

Index and property access without get/set can always be added at a later stage.

@nmn
Copy link
Contributor

nmn commented May 7, 2015

I agree that .get is something that would need to be kept around. That said subscripts would be a huge benefit as well.

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