nemerle icon indicating copy to clipboard operation
nemerle copied to clipboard

Suggestion: add list construction using range not including final

Open qiru opened this issue 8 years ago • 8 comments

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]

qiru avatar Feb 03 '17 08:02 qiru

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].

ArmanHayots avatar Feb 26 '17 09:02 ArmanHayots

@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.

ssrmm avatar Mar 02 '17 21:03 ssrmm

The feature already exists.

qiru avatar Mar 02 '17 22:03 qiru

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

You should reopen this.

ssrmm avatar Mar 02 '17 22:03 ssrmm

@ssrmm really sorry for misreading.

qiru avatar Mar 02 '17 22:03 qiru

@qiru No problem 😄

ssrmm avatar Mar 02 '17 22:03 ssrmm

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

Currently Nemerle not support unpaired brackets.

VladD2 avatar Mar 04 '17 21:03 VladD2

@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).

qiru avatar Mar 04 '17 23:03 qiru