From: "boris_stitnicky (Boris Stitnicky)" Date: 2013-10-26T17:11:10+09:00 Subject: [ruby-core:58046] [ruby-trunk - Feature #9049] Shorthands (a:b, *) for inclusive indexing Issue #9049 has been updated by boris_stitnicky (Boris Stitnicky). @mohawkjoh: Tilde is bad, too. From basic ASCII (I looked), everything is taken, except for ^, and which should be avoided because it means power in many languages. Asking for a new syntax feature in a maturing language is a big deal. I'd stay with Matlab/Octave's colon, if .. and ... are not permissible, but I'd do it outside normal Ruby syntax. Sadly, there is no way to overload : in regular Ruby anymore. Your options are: 1. Settle for strings: "*, 2:4", or "*|2:4" etc. (do we hate quotes). 2. Ask for novel %(some character) literals. But m[ %X(*|2:5) ] is still too much clutter, when one dreams of m[ *, 2:5 ]. (On custom literals, #8807, I voted against, as I thought it would burden noobs. Maybe I was wrong.) 3. Turn to Unicode, as I do in my Pyper, via #method_missing: m.���������0���2���5��� (insane APLism) 4. Use a block instance execced in a special object: m.slice { ��� | (2..5) } 5. Ask for the following syntactic feature: m��� something ��� # ������ are angle brackets or some similar novel delimiters meaning m( "something" ) This feature would rid us of the hated quotes. Then m��� * | 0 + 2:4 ��� would simply mean m( "* | 0 + 2:4" ) where the single string argument you would parse ad libitum. I personally like this last option best, though it is far from problem-free. The delimiters would have to be escaped in the statement body. So this is what I think we should ask from Matz. Varieties would be: m��� some string ���, m��� some string ���, m�� some string ��, m�� some string �� m ��� some string ���, m �� some string ��, etc. ---------------------------------------- Feature #9049: Shorthands (a:b, *) for inclusive indexing https://bugs.ruby-lang.org/issues/9049#change-42625 Author: mohawkjohn (John Woods) Status: Open Priority: Low Assignee: Category: core Target version: =begin For NMatrix, we've implemented a range shorthand which relies on Hashes: (({m[1=>3,2=>4]})), for example, which returns rows 1 through 3 inclusive of columns 2 through 4 (also inclusive). The original goal was to be able to do (({m[1:3,2:4]})) using the new hash notation, but the new hash notation requires that the key be a symbol ��� it won't accept an integer. Whether through the hash interface or not, it'd be lovely if there were a shorthand for slicing matrices (and even Ruby Arrays) using colon. This could just be an alternate syntax for ranges, also ��� which might make more sense. The other related shorthand we'd love to find a way to implement is the all-inclusive shorthand. It gets to be a pain to type (({n[0...n.shape[0],1...3]})) to get a submatrix (a slice), and it's really difficult to read. As a work-around, we currently use the (({:*})) symbol: (({n[:*,1...3]})). But it'd be simpler if there were a way to use a splat operator without an operand as a function argument. It might be a special case where the (({*})) is treated as a (({:*})) automatically. But this edge case might cause confusion with error messages when users make syntax errors elsewhere. The colon shorthand is the highest priority for us. =end -- http://bugs.ruby-lang.org/