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

Suggestion: add list construction using range not including final #13334

Open
qiru opened this issue Feb 3, 2017 · 8 comments
Open

Suggestion: add list construction using range not including final #13334

qiru opened this issue Feb 3, 2017 · 8 comments

Comments

@qiru
Copy link

qiru commented Feb 3, 2017

Please add another way of creating a list which doesn't include final number (like ... in Ruby)

like this:

def l1 = $[0 .. 3]; // an existing way
// [0, 1, 2, 3]
def l2 = $[0 ... 3] // another way
// [0, 1, 2]
@ArmanHayots
Copy link

ArmanHayots commented Feb 26, 2017

I'm sorry, but why you can't just write $[0..2]?
Or if this is actually needed feature, how be with situation when first num must be omitted?
Then maybe math notation like $( .. ),$[ .. ],$[ .. ),$( .. ] fit your needs better?
A.e. construct list with range $[0 .. 3) will give [0, 1, 2].

@ssrmm
Copy link

ssrmm commented Mar 2, 2017

@ArmanHayots I was thinking the same thing. Plus, the visual difference between two and three dots isn't all that big, promoting Off-by-one errors.

$[ .. ) and $( .. ] might be problematic for the syntax highlighting in some editors though.

@qiru
Copy link
Author

qiru commented Mar 2, 2017

The feature already exists.

@qiru qiru closed this as completed Mar 2, 2017
@ssrmm
Copy link

ssrmm commented Mar 2, 2017

@qiru To my knowledge this feature does not yet exist, @ArmanHayots was merely suggesting an alternate syntax for your proposal.

You should reopen this.

@qiru qiru reopened this Mar 2, 2017
@qiru
Copy link
Author

qiru commented Mar 2, 2017

@ssrmm really sorry for misreading.

@ssrmm
Copy link

ssrmm commented Mar 2, 2017

@qiru No problem 😄

@VladD2
Copy link
Member

VladD2 commented Mar 4, 2017

Then maybe math notation like $( .. ),$[ .. ],$[ .. ),$( .. ] fit your needs better?

Currently Nemerle not support unpaired brackets.

@qiru
Copy link
Author

qiru commented Mar 4, 2017

@ArmanHayots

I'm sorry, but why you can't just write $[0..2]?

That's because I feel this notation unnatural (this is completely subjective, though).
When I create a list which begins with 0, I'd prefer $[0 ... length] as it seems natural to me (the notation is just an example).
Like range function in Python.
It looks attractive that Nemerle has both ways, inclusive (..) and exclusive (...) list construction, like Ruby or CoffeeScript.

Then maybe math notation like $( .. ),$[ .. ],$[ .. ),$( .. ] fit your needs better?

The notations you suggested look very good (quite understandable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants