-
Notifications
You must be signed in to change notification settings - Fork 157
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
ES6 #26
Comments
Python has No idea about syntax. |
But yes, I think it could be useful, when es6 would get some browser support, perhaps when chrome / v8 (without flag) and safari would have it. Somewhere around july. perhaps
|
I find maybe some other control character though, |
I like My proposal for syntax for maps and sets is the following: Sets:
Maps:
I've tried it out and it does not conflict with any of the current syntax, and does not require great amounts of modification to the lexer. Thoughts? My idea is to not require a shim or anything, but simply note in the docs that if the user wants to take advantage of these features, they must either be on a platform that supports them, or they must include a shim. |
👍 |
Taking a look at the api, is there no way to mass-set sets and maps instead of doing x.set for each item? |
there will be, a new draft will likely feature |
@paulmillr how will that work for maps though? Also, so far we've only covered the literal syntax of maps an sets, what about adding members/rows and such? |
@adrusi I don't know, TC39 will think of something, likely. For example const set = <(1 2 3 4)>
const map = <{1: 1 2: 2 3: 3 [4]: 4}>
set.add 5
set.add 6
map.set [5], 5
map.get 3 |
Okay, well I'll wait until TC39 finalizes things more before moving forward with this. |
it's interesting that this is fully implemented in firefox when it's so incomplete still. |
also in case someone's interested, i've made a bench http://jsperf.com/es6-shim-vs-es6-collections It's a good replacement for |
@paulmillr looking at your source, it looks like you're using a naïve approach to sets and maps. While it's quite possible that the standard approaches would actually be less efficient without typed arrays (which you unfortunately cant use without another shim due to them not being available in even older engines), I think it would still be worth a shot to use actual hash maps and hash sets. also: speed degradation by "only" ~30% isn't really acceptable performance, sure for a shim it's ok, since it's only used in older platforms, but still. edit 2: sorry if that came across as a bit harsh, that was not intended :) |
@adrusi es6-shim doesn't care about engines that don't support ES5. Except IE8, but it was very easy to make it work there and if it'll break, it ain't a big deal. Currently es6-shim maps / sets performance sucks, but is there really another way of doing the work? I don't think so. JS doesn't have unique IDs, so you can't make a hash function. |
@paulmillr you can't hash the uid of an object, but you could serialize it to JSON or maybe some other format and hash that. That's one of the reasons I wasn't entirely sure it would actually present speed improvements, especially since you would need to compensate for collisions more manually than otherwise. |
If it will be serialized and hashed, then two same objects with different references will map to same map item. It will violate the spec. |
That would solve the problem. For lookup efficiency you use a HashMap, but in order to discriminate between different refs you use an ArrayMap for each hash value. maybe this discussion should be moved to the shim issues page. |
@paulmillr: be creative. If you couldn't make a map from arbitrary objects in ES5, nobody would be able to implement memoisation. And we know that's not the case (beware: very old code). |
@michaelficarra right, if I understand correctly, your implementation does the same thing es6-shim does: iterating through array with check for And performance of it sucks, that's what I point at. It's about ~250 times slower than actual es6 map in Chrome. |
Would love to have a built-in set type. That's the one thing that seems to be missing from LiveScript that I would really want. |
BTW, the proposed syntax for sets will not work. Failure scenario below. 1 <(3)> 2 #=> true |
But what about WeakMaps? For example, |
So I stumbled across https://github.com/paulmillr/es6-shim (cool stuff @paulmillr) and that got me thinking about how we could integrate various ES6 features.
Syntactic sugar for maps and sets?
The text was updated successfully, but these errors were encountered: