Giter Site home page Giter Site logo

Comments (5)

nmn avatar nmn commented on May 21, 2024

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.

from ecmascript-immutable-data-structures.

natew avatar natew commented on May 21, 2024

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.

from ecmascript-immutable-data-structures.

nmn avatar nmn commented on May 21, 2024

@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.

from ecmascript-immutable-data-structures.

andersekdahl avatar andersekdahl commented on May 21, 2024

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.

from ecmascript-immutable-data-structures.

nmn avatar nmn commented on May 21, 2024

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

from ecmascript-immutable-data-structures.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.