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

Remove stepped ranges #12537

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

IanManske
Copy link
Member

@IanManske IanManske commented Apr 16, 2024

Description

This PR removes stepped ranges from the language (e.g., 0..5..20). Why?

  1. Simplifies the language. Supporting stepped ranges potentially makes commands more complex or makes handling arguments more annoying. E.g., range 0..2.. should either error or actually select every other row. (Either way, the every command already covers this use case.)
  2. Related to / because of 1. stepped ranges have limited support. In the process of writing this PR, I didn't find a single command that handled, let alone even used the step value (Some commands that handle ranges don't account for the step value #11521).
  3. Stepped ranges have a potentially confusing syntax (Weird range behavior #11086).
  4. Stepped ranges have limited use cases / add little value. I think the main use case is simply to create a sequence of values. But the seq command already exists, and it should have all the same functionality.
    Edit: stepped ranges would allow for stepped slicing (e.g., like arr[start:end:2] in python). Not sure what the common use case for this is, but I'm guessing 2d arrays and images where a row stride is desired. However, I'm not sure how applicable or useful this would be for nushell. E.g., operations are usually over streams, and the every command already covers stepping behavior for streams.

As a side effect, this PR fixes #9417 (panic while parsing ranges).

User-Facing Changes

This will break existing code that uses stepped ranges. Users will have to switch to using seq.

After Submitting

Update the book and language guide. Language grammars will also need to be updated.

@IanManske IanManske added pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:language This PR makes some language changes labels Apr 16, 2024
@fdncred
Copy link
Collaborator

fdncred commented Apr 16, 2024

I'm not really a fan of removing ranges by step altogether. But I would support changing it to how seq works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:language This PR makes some language changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Off-by-One Access in engine_state.rs?
2 participants