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

Inequality slicing without ..: x[<i] etc. #1547

Merged
merged 2 commits into from
Oct 30, 2024
Merged

Inequality slicing without ..: x[<i] etc. #1547

merged 2 commits into from
Oct 30, 2024

Conversation

edemaine
Copy link
Collaborator

As suggested by @STRd6 on Discord

you can avoid `..` altogether:

<Playground>
x is x[<=i] + x[>i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the x is and + from these examples because === and + on slices aren't how one may expect.

@edemaine edemaine merged commit ec63194 into main Oct 30, 2024
3 checks passed
@edemaine edemaine deleted the slice-ineq branch October 30, 2024 20:04
@JayXon
Copy link

JayXon commented Oct 30, 2024

This is a little confusing because I thought x[>=i] is a reverse slice where .. is omitted

@edemaine
Copy link
Collaborator Author

We discussed this some in Discord (feel free to join us!).

This PR's notation is more like the binary operator sections (< i) and (>= i), and clearly specify the desired index range.

We could of course also spell x[>=i] as x[i<=] (which wouldn't have the same confusion), and I'd be open to adding that as an alternative spelling. But I worry about making x[>=i] a reverse slice: my feeling is that reverse slices are a niche feature, so don't need concise notation, and I don't think it's particularly intuitive that x[>=i] is reversed, so it's not worth making it so for consistency. But happy to continue discussing!

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.

3 participants