From: David MacMahon Date: 2013-10-23T23:15:02-07:00 Subject: [ruby-core:58012] Re: [ruby-trunk - Feature #9049] Shorthands (a:b, *) for inclusive indexing On Oct 23, 2013, at 10:36 PM, boris_stitnicky (Boris Stitnicky) wrote: > @david_macmahon: I do not think that the wish to make a : b an alias of a .. b > can fit into the language anymore. "x > 0 ? 1 : 2 : 3" could be ambiguously > parsed as "x > 0 ? ( 1 : 2 ) : 3" or as "x > 0 ? 1 : ( 2 : 3 )"... Good point. How about if this new notation limited only to uses within square brackets: `[a:b]`? There are two distinct cases (maybe more?). One case is where this used as a literal like `range = [a:b]` and the other where it is used in #[] like `array[a:b]`. It may seem strange for `[...]` to create a non-Array literal, but the usage would be pretty straightforward: ```ruby [a:b] => a..b [a:b, c:d] => [a..b, c..d] [[a:b]] => [a..b] ``` With this case, your example of `x > 0 ? 1 : 2 : 3` would not be syntactically valid, but it could, for example, be re-written as `x > 0 ? [ 1 : 2 ] : 3` (excessive spaces added for emphasis), which would be equivalent to `x > 0 ? 1 .. 2 : 3`. The two cases are mutually exclusive (unless there is some parsing constraint I'm unaware of). The #[] case would be the more useful of the two (by far, IMHO). The [a:b] case doesn't really offer much over the a..b syntax (except for possible consistency with the #[] case). Dave