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

Suggesting new syntax: a..b #8949

Closed
xianrenb opened this issue Nov 9, 2014 · 7 comments
Closed

Suggesting new syntax: a..b #8949

xianrenb opened this issue Nov 9, 2014 · 7 comments

Comments

@xianrenb
Copy link

xianrenb commented Nov 9, 2014

I would suggest that new syntax "a..b" represents "[a, a+1, a+2, ... , b]".
The followings should then become true:
"1..5" represents "[1, 2, 3, 4, 5]".
"reverse(1..5)" represents "[5, 4, 3, 2, 1]".
"1..99[1:2:end]" represents "[1, 3, 5, 7, ..., 99]".

Related issue: #3737

@pao
Copy link
Member

pao commented Nov 9, 2014

Ranges can already do exactly those things. See http://nbviewer.ipython.org/gist/pao/dbd0a405a56afd6dbfa2

(and a special thanks to http://tmpnb.org for making this example straightforward to create)

@pao pao closed this as completed Nov 9, 2014
@xianrenb
Copy link
Author

xianrenb commented Nov 9, 2014

This is exactly the problem.
Ranges are not the same as arrays!
I believe we need to be able to create array of ranges in a concise way. For example, "[1:5, 1:3]" should be an array of two ranges: "1 to 5" and "1 to 3".
Range(s) between "[" and "]" should still be range(s).
Currently, we could convert range to array: "convert(Array, 1:5)" would give "[1, 2, 3, 4, 5]".
"[1:5]" should not equal "[1, 2, 3, 4, 5]".

@StefanKarpinski
Copy link
Sponsor Member

There are already several issues discussing this, which you have linked to – why open a duplicate issue intentionally?

@xianrenb
Copy link
Author

xianrenb commented Nov 9, 2014

Simple, because this is a new syntax.
It may or may not be related to other issues.

@johnmyleswhite
Copy link
Member

New syntax is not something that should be added lightly.

@lindahua
Copy link
Contributor

lindahua commented Nov 9, 2014

You can create an array of ranges using

UnitRange[1:3, 1:5]

@JeffBezanson
Copy link
Sponsor Member

Dense range vectors should be avoided, so I don't think they deserve
special syntax. Something like collect(a:b) is enough.

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

No branches or pull requests

6 participants