-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Change range semantic to behaves more like rust. #12890
Conversation
Make as draft because the decision is not finally made |
Coming to this based on #13077 - As a user, I think the existing semantic is much more logical. I know that various languages and libraries are split on this:
Personally, I see On the flip side, I fully understand that slicing operations should (and must) be based on the rule "0 is the position before the first element, count up from there", which means that > [ 1 2 3 4 ] | range 0..4
[ 1 2 3 ] ... and the same, as you mentioned, for |
@NotTheDr01ds Thanks for your input! Happy to see there are some languages return inclusive pair on something like So I will close the pr |
I support this PR. Rust and Python are very popular languages, with Nushell being written in Rust too. It'll be more familiar for people coming from those, especially when manipulating strings. |
Description
We have decided to make range to behave like rust, that is:
This pr also:
1..<3
syntax. The main change is happened incrates/nu-parser/src/parser.rs:parse_range
crates/nu-cmd-base/src/util.rs
detect_columns
(for-c
flag)str substring
str index-of
(for-r
flag)bytes at
Take
str substring
as example:Before
After
The result of
"abcd" | str substring 1..3
remains unchanged because the semantic of1..3
is changed from[1,2,3]
to[1,2]
, so it returns "bc".Apart from changes in
crates/nu-parser/src/parser.rs:parse_range
andcrates/nu-cmd-base/src/util.rs
, remaining changes are most about adjusting test code to follow new semanticFixes: #7761
User-Facing Changes
It's a big breaking change, because the semantic of
1..3
is changed from[1,2,3]
to[1,2]
Tests + Formatting
Adjusted all tests
After Submitting
Need to update documentation about ranges