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

Allow array slicing #358

Closed
Soares opened this issue Oct 19, 2012 · 2 comments
Closed

Allow array slicing #358

Soares opened this issue Oct 19, 2012 · 2 comments

Comments

@Soares
Copy link
Contributor

Soares commented Oct 19, 2012

Not a big priority, but it would be pretty cool to have python-style array slicing. T'would be a bit different due to the 1-indexing of arrays, but I envision something like this:

> set x a b c d
> echo $x[2:3]
b c
> echo $x[2:]
b c d
> echo $x[:2]
a
@ridiculousfish
Copy link
Member

We have this thanks to maxfl's awesome contribution at #212

> set x a b c d
> echo $x[2..3]
b c

It doesn't allow omitting indexes, but you can use -1 to index from the end.

> set x a b c d
> echo $x[2..-1]
b c d

also note that ranges are inclusive, which is a little weird, but makes sense when you consider that fish indexes starting from 1. So

> echo $x[1..(count $x)]
a b c d

ought to output everything.

@Soares
Copy link
Contributor Author

Soares commented Oct 19, 2012

Sweeeet! Should have read the manual harder before posting, my apologies.

@Soares Soares closed this as completed Oct 19, 2012
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants