I've been thinking on how I would go about designing the perfect range literal if I were to do design a language.  For you that don't know know a range literal in a statement that represents a range of values, like  1-4. They're most commonly used in for/foreach loopsThere seems to a couple of issues one should take into accountSupport for inclusive andexclusive ranges, tacking on +1 or -1to endpoints seems a bit fugly anderrorprone.Support for stepping, so you canmake a range of even or odd numbersfor instanceReadability, it should be readilyapparent what the range literaldescribesUnambiguity, it should beperfectly unambigious what the rangeliteral describesThe default should probably be from inclusive to exclusive since that's what's used in     most cases for looping over arrays etc.Anyways, one example of  range literal I've seen is Ruby which is in the form of 1..3 for an exclusive (on the end) range and 1...3 for inclusive (on the end). You can also do  1..10.step(5). After careful consideration I found however a couple of things I didn't like about that approach (from my limited knowledge of ruby)You can only describe inclusiveand exclusive for the end. Whiledescribing most scenarios it doesseem  a little inconsistent.  Varying by just an additional .seems like a recipe for making ithard to see whether a range isinclusive or exclusive. I don't knowabout you but dot's tend to becomesomething of a blur :)Adding method like notation forranges seems to mix the notion of aliteral with that of a class whichseems a bit inconsistent (even ifranges get compiled to a class)Anyways, after pondering different alternatives. I came up with this[5..1]     5,4,3,2,1[1..5[     1,2,3,4]1..5]     2,3,4,5 [0..5..20] 0,5,10,15,20and so forth. I like it because [ normally denonates a set and this kinda fits into that, even though this in contrast to a  set would be ordered. One thing I'm a bit torn about though is making the exclusive/inclusive indicators mandatory or not, ie if you write  just 1..5  the default would be 1,2,3,4 since it's the most common case with arrays etc.  It's easier and more readable, but less specific and if you had to write [1..5[ you learn early about how they work.So what do you think, did I cover most bases, overlook something? would you make the [] mandatory? Would you design range literals differently in your programming language?Candidatesbracket style: [0..10[  , with step:  [0..5..20[interval notation: [0..10)  with step: [0..5..20)exclamation for exlusive.  0..!10, with step: 0..5..!20with different step.  0..!20, 5however, that would make the default *0..10' inclusive-inclusivewordy: [0 to !20 by 5]I must say that my favorite aestically so far is 0..!10 and 0..5..!20, I just wish the default 0..10 to inclusive-exclusive would be more logical
Designing the perfect range literal
programming languages;design
And the winner isSorry for chosing my own solution, I really appreciate all the comments and feedback and please do critize this solution if you find anything wrong with itSo I decided to go with:0..5           = 0,1,2,3,50..5..10       = 0,5,10..3            = 0,1,3!0..!5         = 1,2,3,43..            = 3 to infinitysegmented ranges-0..5,..5..20   = 0,1,2,3,4,5,10,15,200..3,10..5..20 = 0,1,2,3,10,15,20As you can see inclusive is the default on both senses, it's what makes intuitively most sense especially when using stepping. You can use ! to make an end exclusive. The downside is that normally you want to use exclusive when working against an array, but then again, most times you should probably be using something like for-each in those cases. If you really really need to work against the index the parser could recognize when you possibly forgot the exclusion marker on the end and issue a warningI went with using .. on both sides of the step variable instead of using comma or anything else since that's what looked cleanest and I hope is the most readable.I also threw in some syntax with comma's to be able to make ranges where different parts have different steps