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

extension to slice-expression #32

Closed
wants to merge 1 commit into from
Closed

extension to slice-expression #32

wants to merge 1 commit into from

Conversation

caub
Copy link

@caub caub commented Aug 20, 2019

I propose to rename this proposal to "proposal-slice-expression", because I propose to have a syntactic representation for the SliceExpression, and 2 behaviors:

  • if a sliceExpression is the property of a (dynamic) MemberExpression, it will evalutate to object[Symbol.slice](sliceExpression.startIndex, sliceExpression.endIndex, sliceExpression.step) (cf Consider basing the semantics on a method call #1)
  • else, it will evaluate to an iterator:
(function* (si, ei, step) {
  if (step < 0) {
    for (let i = ei - step; i >= si; i += step) yield arr[i];
  } else {
    for (let i = si; i < ei; i += step) yield arr[i];
  }
})(sliceExpression.startIndex, sliceExpression.endIndex, sliceExpression.step)

@rbuckton proposed something similar in #19, I think we should not consider AssignmentExpression (arr[0:2] = [3,4]) because strings are immutable, the added complexity is probably not worth either

@caub caub force-pushed the patch-1 branch 3 times, most recently from 35bc803 to 60e7d49 Compare August 20, 2019 16:21
@gsathya
Copy link
Member

gsathya commented Jun 23, 2020

if a sliceExpression is the property of a (dynamic) MemberExpression, it will evalutate to object[Symbol.slice](sliceExpression.startIndex, sliceExpression.endIndex, sliceExpression.step) (cf #1)

This seems like a fine idea.

else, it will evaluate to an iterator:

This is best left to the range proposal: https://github.com/tc39/proposal-Number.range
I want the slice notation to do just one thing, not several things depending on the context. Given that, I don't think it makes much difference whether it's called slice expression or slice notation (unless I'm missing something).

@gsathya gsathya closed this Jun 23, 2020
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.

2 participants