nemerle
nemerle copied to clipboard
Suggestion: add list construction using range not including final
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]
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 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.
The feature already exists.
@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 really sorry for misreading.
@qiru No problem 😄
Then maybe math notation like $( .. ),$[ .. ],$[ .. ),$( .. ] fit your needs better?
Currently Nemerle not support unpaired brackets.
@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).